Generating Cookies Through Form
Posted: Mon Apr 02, 2007 6:41 pm
So, I'm trying to slog my way through the world of PHP, and for whatever reason, I can't get a form to set/generate a cookie. The solution is currently beyond me and so I turn to the masters.
The case at hand, is I need a form that a user can either accept or not, terms set by the company. If they do acept the terms, I need to set a cookie so that don't have to agree to terms rarely, if at all. However, my issue begins with getting the form to create the cookie, which means I can't do anything else.
The code:
I'm sorry if something liek this has been posted before, I did a search and didn't find anything that addressed my needs. Any help on this would be greatly appreciated.
The case at hand, is I need a form that a user can either accept or not, terms set by the company. If they do acept the terms, I need to set a cookie so that don't have to agree to terms rarely, if at all. However, my issue begins with getting the form to create the cookie, which means I can't do anything else.
The code:
Code: Select all
<?php
// if form was submitted, handle it
if(isset ($_POST['submit'])) {
//sending to cookie monster
setcookie ('termsAgree', $_POST['termsAgree'], time()+30000000000000, '/', '', 0);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
<meta name="generator" content="Adobe GoLive" />
<title>Poo bear Agreement</title>
</head>
<body>
<?php
// if cookies were sent, print message
if (isset ($_COOKIE['termsAgree'])) {
print 'You have accepted the terms you may <a href="#">proceed</a>.';
} else {
print '<p>In order to go any further along this process, you must agree to SHOOP Terms and Conditions.</p>';
}
?>
<form action="terms.php" method="post">
<input type="radio" name="termsAgree" value="termsAgree" /> Agree
<input type="radio" name="termsDagree" value="termsDagree" /> Disagree
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>I'm sorry if something liek this has been posted before, I did a search and didn't find anything that addressed my needs. Any help on this would be greatly appreciated.