WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
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 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
פרייסז - השוואת מחירים בסופר
ZeroLag.com
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this Article 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 SUBMIT AN ARTICLE PRINT
Title : User identification using cookies in PHP and MySQL
Categories : PHP, Databases, MySQL, Cookies
devarticles
devarticles
Date : 2004-04-17
Grade : 3 of 5 (graded 2 times)
Viewed : 16380
Search : More Articles by devarticles
Action : Grade This Article
Tools : My Favotite Articles


Submit your own code examples 
 


What is a cookie and how do we use them in PHP? If you can not answer this question, you should definitely have a read through this article.
This article will explain the basics and possibilities of user identification using cookies. First of all the mechanics of cookies must be explained in order to understand what can be passed to cookies and how well protected that information is.

Cookies are ASCII files that browsers store in temporary internet directories. These files are set by internet webpage, either through HTTP header properties, or by using javascript code. Therefore, the browser is the one responsible of storing the cookie files, by request of the viewed page. All that gets transmitted from remote page is a set of variables the cookie should contain. A cookie contains several variables that are important to us:

* name string
* information string, called VALUE
* expiration time
* relevant host address
* relevant host directory

Name is cookies name. By this name it will be identified in our script.

The value is a string that can carry certain information. In our case, it will hold the data user is identified by. Expiration time is number of seconds passed since January 1., 1970., midnight GMT. Therefore, it represents accurate date/time combination when the cookie is no longer valid. The host address identifies the host this cookie will be transmitted to, and the directory represents hosts subdirectory which should receive this cookie.

In other words, by setting the address and directory you somewhat ensure that only files contained within that directory and on that host will receive the cookie. For example, you have a script called identify.php with the following url:

www.somedomain.com/somedirectory/identify.php

To ensure only identify.php will receive the desired cookie, the cookies host address must be .somedomain.com and the directory must be /somedirectory/. Browsers will recognize the addres/directory combination and will pass the cookie to the identify.php script. Note that domain address has a dot as the first character. This ensures that any prefix validates the domain, prefixes being www or ftp or any other.

So the mechanism is this: browsers register domains and directories for all cookies stored in a local directory. When the browser is directed to a particular URL, only the cookies that are registered for that URL (domain/directory combination) will be passed to a HTML or PHP file in that URL, along with all those cookies that do not have domain address nor host directory set (which are in that case passed to all URLs browsers are directed to). Also, only those cookies that have not yet expired will be passed. Expired cookies will be deleted from local computers by the browser.

This article assumes that the reader is familiar with PHP programming and usage of MySQL databases.

Read More...









Building A Persistent Shopping Cart With PHP and MySQL
Categories : PHP, MySQL, Databases, Ecommerce
Case Study: Handling MySQL Growth With a PHP Class
Categories : Databases, MySQL, PHP
PHP, MySQL and Authentication 101
Categories : PHP, Databases, MySQL, Authentication
Practical Date and Time examples with PHP and MySQL
Categories : Databases, MySQL, PHP, Date/time
Miles To Go Before I Sleep...
Categories : PHP, Calendar, Databases, MySQL
Simple Connection to MySQL with PHP
Categories : PHP, MySQL, Databases
Time Is Money Part 1 of 2 - Designing and implementing a Web-based application
Categories : PHP, Databases, MySQL, Complete Programs
Alternating row colors with PHP and mySQL
Categories : PHP, Databases, MySQL, HTML and PHP
Date Arithmetic With MySQL
Categories : PHP, Databases, MySQL, Date Time
Multicolumn Output from a Database with PHP
Categories : PHP, Databases, HTML and PHP, MySQL
PHP and MySQL News with Comments
Categories : PHP, Databases, MySQL
How To add paging (Pagination) with PHP and MySQL
Categories : PHP, Beginner Guides, Databases, MySQL, HTML and PHP
Custom MySQL-functions
Categories : Databases, MySQL, PHP, PHP Functions
Saving Images in MySQL
Categories : MySQL, PHP, Graphics, Databases
Watching The Web
Categories : PHP, Databases, MySQL, HTTP, MD5