<?
// cookie.php3
//
// by Jeff Schmitt
// Towson University
// March, 1998
//
/*
Date: Wed, 8 Apr 1998 01:51:04 -0400
From: "Brian M. Platz" <platz.brian@infoband.com>
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";