Date: Wed, 8 Apr 1998 01:51:04 -0400
From: "Brian M. Platz" <[email protected]>

The syntax is:

SetCookie($name,$value,$expire_time,$directory,$domain,$secure);
$name - name of the cookie

$value - value of the cookie

$expire_time - [optional] time in UNIX epoch seconds when cookie should
expire. This is optional, and if not specified will expire after
the user 'session', or after they exit your domain/directory
specified.

$directory - [optional] directory under web server this cookie is for.
Defaults to the directory of the requested page.

$domain - [optional] domain name this cookie can be used under.
Defaults to domain name of requested page. Must have TWO '.' in the
name, so if you specify your A level, you must use ".mydomain.com"

$secure - [optional] if set to '1', this cookie will only be sent over
secure server, or an 'https://' request.

if your document is /mydir/index.php3 and you set a cookie using
SetCookie("mytest", "this is a test cookie");
you will only be able to access $mytest for document under the /mydir/
directory tree.

To set a cookie that will expire after the current session, and will work
for your entire domain.. use the following:
SetCookie("mytest", "this is a test cookie", 0, "/", ".yourdomain.com");

As for retrieving the value of a cookie, it is automagically URL decoded
and put in a variable.

As for "if (!SetCookie("mytest", "this is another test")) {",
I don't think SetCookie() returns a value. I could be wrong.

-Brian Platz

*/

// This code must go before the HTML header has been sent
// in other words it preceedes all echo and <HTML> code

// we increment a hard-coded cookie variable: $cookiecount
SetCookie("cookiecount", ++$cookiecount, 0, "/", ".towson.edu");


// look at the HTML form variables
if ($action) {
// set the cookie variable
// append "cookie" to name of the variable
// so it can easily be found in list of global variables
SetCookie("cookie".$name, $value, 0, "/", ".towson.edu");
echo "<P>Setting Cookie: $name to $value<BR>\n";
echo "(reload this form to see if this value is reported)\n";

}

?>
<HTML><HEAD>
<TITLE>cookie test</TITLE>
</HEAD>
<BODY>
<H2>cookie test</H2>

<?
echo "<P>Reporting your cookies:<BR>\n";
while (list($key, $value) = each($GLOBALS)) {
// report variables starting with cookie
// or PWD or UNAME -- these are from bannerad.php3 login
if (ereg('cookie|PWD|UNAME',$key)) {
echo "$key: $value<BR>\n";
}
}

?>

<HR NOSHADE>
<H3> Set some cookie values: </H3>
<FORM METHOD="POST" ACTION="<?echo $PHP_SELF;?>">
<TABLE BORDER=1>
<TR><TH>Name:
<TD><INPUT NAME="name" size=8 MAXLENGTH=8>
<TH>Value:
<TD><INPUT NAME="value" size=30 MAXLENGTH=30>
<TR><TH>Action:
<TD><INPUT TYPE="SUBMIT" NAME="action" VALUE="Submit">
<TD><INPUT TYPE=RESET VALUE="Clear Form">
</TABLE>
</FORM>
</BODY>
</HTML>