Associate
- Joined
- 2 Nov 2007
- Posts
- 488
Hello all,
Id really appreciate some help using sessions in my PHP contact form.
What i would like to achieve is a way limiting each user to submitting the form once every 60 seconds (so im not overrun by Spam). I was thinking of creating some session based on the user's IP (or SID - but i dont really understand that) and just checking the session data.
However, i dont understand fully how sessions work, this is what i currently have:
But PHP is giving me warnings about modifying session data.
Sorry im being a bit vague, its just im not too sure what the best way to implement sessions are.
I would really appreciate some help.
Cheers
Id really appreciate some help using sessions in my PHP contact form.
What i would like to achieve is a way limiting each user to submitting the form once every 60 seconds (so im not overrun by Spam). I was thinking of creating some session based on the user's IP (or SID - but i dont really understand that) and just checking the session data.
However, i dont understand fully how sessions work, this is what i currently have:
Code:
//Start the session
$session = session_id();
if($session == "") {
session_start();
}
//Check if the a message has been sent in the last 60 seconds
$timeLimit = $_SESSION['lastMailed'] + 60 < time();
if (!$timeLimit && $_SERVER['REMOTE_ADDR'] = $_SESSION['ip']) {
$response['error']['time'] = 'Whoah, slow down there! Please wait 60 seconds before sending another enquiry';
}
//blah blah check the POST data and send the email
//Start timing from when the message was sent
$_SESSION['lastMailed'] = time();
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
But PHP is giving me warnings about modifying session data.
Sorry im being a bit vague, its just im not too sure what the best way to implement sessions are.
I would really appreciate some help.
Cheers