|
|
|
<?
// 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";
}
?>
<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)) {
if (ereg('cookie',$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> |
|
| PHP4 MYSQL Authentication Script with cookie. Short & Sweet
Categories : Authentication, Apache, Cookies, PHP, MySQL | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | | | Authentication script to authenticate users in Active Directory through LDAP. Categories : LDAP, Authentication, Cookies, PHP | | | Example voting script. Lets people enter suggestions and vote for existing ones. Categories : MySQL, PHP, Cookies, Complete Programs, Databases | | | Function that allows a Javascript cookie to be set after HTML has been outputted to the page.
Categories : PHP, Java Script, Cookies, HTML and PHP | | | The Best Authorize Categories : PHP, MySQL, Cookies | | | Secure Login Categories : PHP, MySQL, Cookies, Security | | | Simple Cookie example Categories : PHP, Beginner Guides, Cookies | | | With this class you can use cookies with chips Categories : PHP, Cookies | | | Query2Report : Generating Html, Pdf and Csv Reports from SQL Query Categories : PHP, PHP, HTML, PDF, Excel | | | How to make sure a that $foo is from a cookie and not from the URI. Categories : PHP, Variables, Global Variables, Cookies | | | Cross Browser Session Starter Categories : PHP, Sessions, Cookies | | | Function that does language negotiation based on the Accept-Language header, a cookie or host name Categories : HTTP, PHP, Cookies | | | Store, retrieve and delete cookies using JavaScript. Categories : Java Script, Cookies, Beginner Guides, Cookies | | | Make old style (PHP3) scripts using GET, POST, COOKIE and File uploads (POST) compatible with
PHP 4.2.0 Categories : PHP, HTML and PHP, Global Variables, Cookies, Variables | |
|
|
|