Skip to content

Instantly share code, notes, and snippets.

@jarsen
Created May 25, 2010 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarsen/412805 to your computer and use it in GitHub Desktop.
Save jarsen/412805 to your computer and use it in GitHub Desktop.
<?php
if(isset($_REQUEST['name'])) {
// echo "Setting cookie...";
if(!setcookie($_REQUEST['name'],$_REQUEST['value'],time() + $_REQUEST['exp'])) {
echo "ERROR: cookie not set!";
}
}
?>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Homework 3 | Problem 2</title>
</head>
<body>
<h1>Cookie Factory</h1>
<form action="hw3.php" method="post">
<table>
<tr><td>Cookie Name: </td><td><input type="text" name="name" /></td></tr>
<tr><td>Cookie Value: </td><td><input type="text" name="value"/></td></tr>
<tr><td>Cookie Expiration: </td><td><input type="text" name = "exp"/></td></tr>
</table>
<p><input type="submit"/> </p>
</form>
<?php if(!empty($_COOKIE)) {
print_r($_COOKIE);?>
<h2>Cookies on your machine:</h2>
<table>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<?php foreach(array_keys($_COOKIE) as $key) {?>
<tr>
<td><?php echo $key?></td>
<td><?php echo $_COOKIE[$key]?></td>
</tr>
<?php } // end foreach ?>
</table>
<?php } // end if?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment