First I created an index page with the form and a check for the cookie.
PHP Code:
<?php
if(isset($_COOKIE['FaskenDirectory'])) {
$preference = $_COOKIE['FaskenDirectory'];
header("location:main.php?city=$preference");
exit;
}
?>
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Directory</title>
<link href="styles.css" rel="stylesheet" type="text/css">
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="images/favicon.ico" rel="icon" type="image/x-icon" />
</head>
<body>
<div id="wrapper">
<div id="content">
<p class="head">Please select your home city.</p>
<form name="FaskenDirectory" method="post" action="setcookie.php">
<table cellpadding="10">
<tr><td><input name="city" type="radio" VALUE="Vancouver">Vancouver</td>
<td><input name="city" type="radio" VALUE="Calgary">Calgary</td>
<td><input name="city" type="radio" VALUE="Toronto">Toronto</td>
<td><input name="city" type="radio" VALUE="Ottawa">Ottawa</td>
<td><input name="city" type="radio" VALUE="Montreal">Montreal</td>
<td><input name="city" type="radio" VALUE="Quebec">Quebec</td>
<td><input name="city" type="radio" VALUE="London">London</td>
<td><input name="city" type="radio" VALUE="Paris">Paris</td>
<td><input name="city" type="radio" VALUE="Johannesburg">Johannesburg</td></tr>
<tr><td colspan="9"><input type="image" value="Submit" src="images/select.jpg" border="0"></td></tr>
</table>
</form>
</div>
</div>
</body>
</html>
Then I created a second page to set the cookie
PHP Code:
<?php
$month = 2592000 + time();
if($_POST['Submit']){
$city=$_POST['city'];
}
setcookie("FaskenDirectory", $city, $month);
header("location:main.php?city={$_POST[city]}");
?>
Bookmarks