<?php

error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);      //all error but warnigns & notices

//setting a cookie in HTTP
//Set-Cookie: name=value; [expires=date;] [path=dir;] [domain=name;] [secure]
//expiration date is in format of  "Day, DD Mth YYYY hh:mm:ss GMT" (e.g. Sun, 23 Oct 2006 00:00:00 GMT)

//setting a cookie in PHP
//setcookie(name, value, expirationDate, path, domain);  
//expiration date is in format of time() + number of seconds

if ($_GET[option]=='set')
{
    $newCookie = $_POST["cookie"];                          //get all the form fields
    $newValue  = $_POST["value"];
    $expire    = $_POST["expire"];

    $expiration = time() + $expire * 24*60*60;              //compute expiration seconds 

    setcookie($newCookie, $newValue, $expiration, '/');     //set/save the cookie

    header("Location: $_SERVER[PHP_SELF]");                 //redirect to itself 
                                                            //to ensure that cookies are
                                                            //truly set by the browser
}
?>                          

<html>
<head>
<title>Cookies Set/Get</title>
</head>

<body bgcolor=lightyellow>
<h1>Create and Read Cookies</h1>

<h2>Your Cookies Are:</h2>

<table border=2 bgcolor=tan>
<tr bgcolor=cccccc><th><i>Cookie Name<th><i>Cookie Value</th>

<?php

//  while (list($cookie, $value) = each($_COOKIE))          //loop through $_COOKIE array
        
    foreach ($_COOKIE as $cookie => $value)                 //loop through $_COOKIE array
        print  "<tr><td><b>$cookie<td>$value \n";           //print cookie name & value

    print "</table>";
    
    if (!$_COOKIE)
        print "<h4>There are no cookies, or browser does not accept cookies</h4>"; 
?>

<?php include "../include.php"; ?>      <!-- hyperlink to see the code -->
</body>
</html>