cookie to pevent multiple submissions doesn't work
Posted: Mon Mar 03, 2003 10:18 am
cookie not working
Hi
I have a script which handles info coming from a html form. I wish to stop multiple submissions by making the user wait 60 seconds before its possible to re-submit.
I have this working correctly in one script but the identical code pasted into another script no longer works.
Firstly, this is the script which works
PHP:--------------------------------------------------------------------------------
<?php
if($sentemail == "2"){
include("sorry.php");
}else{
$sentmessage = $sentmessage + 1;
$num = $sentmessage;
setcookie("sentemail","$num",time()+60); //set the cookie
$email = "Sender Name:\t$name\nSender E- Mail:\t$thereemail\nMessage:\t$message\n\n";
$to = "***************";
$subject = "Site Message";
$mailheaders = "From: $thereemail <> \n";
$mailheaders .= "Reply-To: $thereemail\n\n";
mail($to, $subject, $email, $mailheaders);
include("thanksecho.php");
if ($thereemail != "") {
$to = $thereemail;
$subject = "anything here";
$message =
"Thank you for sending a message to the Fan Club
We will have now recieved your message and will send you a reply very soon
Below you will see a copy of the details you sent us
// Title: $title
// First Name: $firstname
// Last Name: $lastname
E-mail Address: $thereemail
// Town: $town
// Country: $country
// Message: $mess
Thank's again for your message
<a href="http://www.anything.com" target="_blank">http://www.anything.com</a>";
mail($to, $subject, $message, "From: fanclub@somewhere.com\r\nReply-To: someoneelse@mycompany.com");
}
}
?>
--------------------------------------------------------------------------------
But when I insert this cookie setting code into the next script it doesn't work - why? (it goes through to thanksecho.php everytime, even if I re-submit a few seconds after the first submit. Why is it not presenting the sorry.php page.
PHP:--------------------------------------------------------------------------------
<?php
/* This page receives and handles the data generated by "peter_form2.php". */
// Trim the incoming data.
$firstname = trim ($firstname);
$surname = trim ($surname);
$street = trim ($street);
$county = trim ($county);
$postcode = trim ($postcode);
$telephone = trim ($telephone);
$mobile = trim ($mobile);
$email = trim ($email);
$job = trim ($job);
$org = trim ($org);
$orgweb = trim ($orgweb);
$level_1 = trim ($level_1);
$level_2 = trim ($level_2);
$comments = trim ($comments);
$date1 = trim ($date1);
$date2 = trim ($date2);
$date3 = trim ($date3);
$time_1 = trim ($time_1);
$time_2 = trim ($time_2);
$time_3 = trim ($time_3);
// Set the variables for the database access:
$Host = "**********";
$User = "****";
$Password = "*******";
$DBName = "******";
$TableName = "feedback";
$Link = mysql_connect ($Host, $User, $Password);
$Query = "INSERT into $TableName values ('0', '$firstname', '$surname', '$street', '$county', '$postcode', '$telephone', '$mobile', '$email','$job', '$org', '$orgweb', '$level_1', '$level_2', '$comments', '$date1', '$date2', '$date3', '$time_1', '$time_2', '$time_3')";
mysql_db_query ($DBName, $Query, $Link);
mysql_close ($Link);
if($sentemail == "2"){
include("sorry.php");
}else{
$num = $sentmessage + 1;
setcookie("sentemail","$num",time()+60); //set the cookie
$message = "A potential client has just submitted the following data\n
Sender FirstName:\t$firstname\n
Surname:\t$surname\n
Street:\t$street\n
County:\t$county\n
Postcode:\t$postcode\n
Telephone:\t$telephone\n
Mobile:\t$mobile\n
Postcode:\t$surname\n
E- Mail:\t$email\n
Job Title:\t$job\n
Your Organisation:\t$org\n
Your Organisation's Web Address:\t$orgweb\n
Area of Focus:\t$level_1\n
Area of Coaching Focuss:\t$level_2\n
You submitted the following comments:\t$comments\n
First Choice Date:\t$date1\n
First Choice Time:\t$time_1\n
Second Choice Date:\t$date2\n
Second Choice Time:\t$time_2\n
Third Choice Date:\t$date3\n
Third Choice Time:\t$time_3\n\n";
$to = "*************";
$subject = "New Client Submission";
$mailheaders = "From: $email <> \n";
$mailheaders .= "Reply-To: $email\n\n";
mail($to, $subject, $message, $mailheaders);
include("thanksecho.php");
if ($email != "") {
$to = $email;
$subject = "Confirmation from Catalysys";
$message =
"Thank you for requesting a trial coaching session.
Your submission will be given priority status and we will be contacting you in the near future.
Below you will see a copy of the details you sent us
Sender FirstName:\t$firstname\n
Surname:\t$surname\n
Street:\t$street\n
County:\t$county\n
Postcode:\t$postcode\n
Telephone:\t$telephone\n
Mobile:\t$mobile\n
Postcode:\t$surname\n
E- Mail:\t$email\n
Job Title:\t$job\n
Your Organisation:\t$org\n
Your Organisation's Web Address:\t$orgweb\n
Area of Focus:\t$level_1\n
Area of Coaching Focuss:\t$level_2\n
You submitted the following comments:\t$comments\n
First Choice Date:\t$date1\n
First Choice Time:\t$time_1\n
Second Choice Date:\t$date2\n
Second Choice Time:\t$time_2\n
Third Choice Date:\t$date3\n
Third Choice Time:\t$time_3\n\n";
mail($to, $subject, $message, "From: *****************\r\nReply-To: peterb@catalysys.co.uk");
}
}
?>
Hi
I have a script which handles info coming from a html form. I wish to stop multiple submissions by making the user wait 60 seconds before its possible to re-submit.
I have this working correctly in one script but the identical code pasted into another script no longer works.
Firstly, this is the script which works
PHP:--------------------------------------------------------------------------------
<?php
if($sentemail == "2"){
include("sorry.php");
}else{
$sentmessage = $sentmessage + 1;
$num = $sentmessage;
setcookie("sentemail","$num",time()+60); //set the cookie
$email = "Sender Name:\t$name\nSender E- Mail:\t$thereemail\nMessage:\t$message\n\n";
$to = "***************";
$subject = "Site Message";
$mailheaders = "From: $thereemail <> \n";
$mailheaders .= "Reply-To: $thereemail\n\n";
mail($to, $subject, $email, $mailheaders);
include("thanksecho.php");
if ($thereemail != "") {
$to = $thereemail;
$subject = "anything here";
$message =
"Thank you for sending a message to the Fan Club
We will have now recieved your message and will send you a reply very soon
Below you will see a copy of the details you sent us
// Title: $title
// First Name: $firstname
// Last Name: $lastname
E-mail Address: $thereemail
// Town: $town
// Country: $country
// Message: $mess
Thank's again for your message
<a href="http://www.anything.com" target="_blank">http://www.anything.com</a>";
mail($to, $subject, $message, "From: fanclub@somewhere.com\r\nReply-To: someoneelse@mycompany.com");
}
}
?>
--------------------------------------------------------------------------------
But when I insert this cookie setting code into the next script it doesn't work - why? (it goes through to thanksecho.php everytime, even if I re-submit a few seconds after the first submit. Why is it not presenting the sorry.php page.
PHP:--------------------------------------------------------------------------------
<?php
/* This page receives and handles the data generated by "peter_form2.php". */
// Trim the incoming data.
$firstname = trim ($firstname);
$surname = trim ($surname);
$street = trim ($street);
$county = trim ($county);
$postcode = trim ($postcode);
$telephone = trim ($telephone);
$mobile = trim ($mobile);
$email = trim ($email);
$job = trim ($job);
$org = trim ($org);
$orgweb = trim ($orgweb);
$level_1 = trim ($level_1);
$level_2 = trim ($level_2);
$comments = trim ($comments);
$date1 = trim ($date1);
$date2 = trim ($date2);
$date3 = trim ($date3);
$time_1 = trim ($time_1);
$time_2 = trim ($time_2);
$time_3 = trim ($time_3);
// Set the variables for the database access:
$Host = "**********";
$User = "****";
$Password = "*******";
$DBName = "******";
$TableName = "feedback";
$Link = mysql_connect ($Host, $User, $Password);
$Query = "INSERT into $TableName values ('0', '$firstname', '$surname', '$street', '$county', '$postcode', '$telephone', '$mobile', '$email','$job', '$org', '$orgweb', '$level_1', '$level_2', '$comments', '$date1', '$date2', '$date3', '$time_1', '$time_2', '$time_3')";
mysql_db_query ($DBName, $Query, $Link);
mysql_close ($Link);
if($sentemail == "2"){
include("sorry.php");
}else{
$num = $sentmessage + 1;
setcookie("sentemail","$num",time()+60); //set the cookie
$message = "A potential client has just submitted the following data\n
Sender FirstName:\t$firstname\n
Surname:\t$surname\n
Street:\t$street\n
County:\t$county\n
Postcode:\t$postcode\n
Telephone:\t$telephone\n
Mobile:\t$mobile\n
Postcode:\t$surname\n
E- Mail:\t$email\n
Job Title:\t$job\n
Your Organisation:\t$org\n
Your Organisation's Web Address:\t$orgweb\n
Area of Focus:\t$level_1\n
Area of Coaching Focuss:\t$level_2\n
You submitted the following comments:\t$comments\n
First Choice Date:\t$date1\n
First Choice Time:\t$time_1\n
Second Choice Date:\t$date2\n
Second Choice Time:\t$time_2\n
Third Choice Date:\t$date3\n
Third Choice Time:\t$time_3\n\n";
$to = "*************";
$subject = "New Client Submission";
$mailheaders = "From: $email <> \n";
$mailheaders .= "Reply-To: $email\n\n";
mail($to, $subject, $message, $mailheaders);
include("thanksecho.php");
if ($email != "") {
$to = $email;
$subject = "Confirmation from Catalysys";
$message =
"Thank you for requesting a trial coaching session.
Your submission will be given priority status and we will be contacting you in the near future.
Below you will see a copy of the details you sent us
Sender FirstName:\t$firstname\n
Surname:\t$surname\n
Street:\t$street\n
County:\t$county\n
Postcode:\t$postcode\n
Telephone:\t$telephone\n
Mobile:\t$mobile\n
Postcode:\t$surname\n
E- Mail:\t$email\n
Job Title:\t$job\n
Your Organisation:\t$org\n
Your Organisation's Web Address:\t$orgweb\n
Area of Focus:\t$level_1\n
Area of Coaching Focuss:\t$level_2\n
You submitted the following comments:\t$comments\n
First Choice Date:\t$date1\n
First Choice Time:\t$time_1\n
Second Choice Date:\t$date2\n
Second Choice Time:\t$time_2\n
Third Choice Date:\t$date3\n
Third Choice Time:\t$time_3\n\n";
mail($to, $subject, $message, "From: *****************\r\nReply-To: peterb@catalysys.co.uk");
}
}
?>