I have a form that I only want used once every hour per customer. So I have set a cookie with an hour long limt. This works fine, but it the user does not allow cookies they can then use the form as much as they want.
I have written this but it does not appear to work, for the reason I do not think one can check immediatly if a cookie set..
Unless I can set an incrementing value to the Cookie, and if that value is more than one then it will redirect that way I can set the cookie on the form page and check for it on the script.
<?php
//Check if Cookie Existis
if(isset($_COOKIE['YankeeForm']))
{
//If the Cookie Exists Let Redirect Them
$redirect = "http://www.xxx.com/Form_Error.php";
header(sprintf("Location: %s", $redirect));
exit;
}
else
{
//Cookie does not Exist So Lets Set it.
$value = 'Yankee_Form';
setcookie('YankeeForm', $value, time()+3600, '/', 'www.xxx.com');
//Lets see if the cookie was accepted
//If So Run Form
if(isset($_COOKIE['YankeeForm']))
{
$msg = "This email has been sent from the Yankee Equipment Systems, Inc. Web Site/n";
$msg .= "----------------------------------------------------\n";
$msg .= "Company Name: $_POST[PMCompany]\n";
$msg .= "Contact Name: $_POST[PMName]\n";
$msg .= "Address: $_POST[PMAddress]\n";
$msg .= "City: $_POST[PMCity]\n";
$msg .= "State: $_POST[PMState]\n";
$msg .= "Zip Code: $_POST[PMZip]\n";
$msg .= "Phone Number: $_POST[PMPhone]\n";
$msg .= "Fax Number: $_POST[PMFax]\n";
$msg .= "Email Address: $_POST[PMEmail]\n";
$msg .= "Message:\n";
$msg .= "$_POST[PMInfo]";
$to = "jjones@xxx.com";
$subject = "PM Agreement";
$mailheaders = "From: Yankee Equipment Systems, Inc. Web SIte \n";
$mailheaders .= "Reply-To: $_POST[PMEmail] \n";
$redirect = "http://www.xxx.com/Thanks.php";
mail($to, $subject, $msg, $mailheaders);
header(sprintf("Location: %s", $redirect));
}
//If Not Accepted Redirect
else
{
$redirect = "http://www.xxx.com/Cookie_Error.php";
header(sprintf("Location: %s", $redirect));
exit;
}
}
?>
Any ideas?