WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : cookie
Categories : Cookies, PHP Update Picture
Jeff Schmitt
Date : May 07th 1998
Grade : 2 of 5 (graded 4 times)
Viewed : 17550
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Jeff Schmitt
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
// 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