ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.


PHP and Cookies; a good mix!

(Page 5 out of 5)

Cookies are really versatile, and can be used for a lot of different purposes. Many websites use cookies, and cookies can really make your website more personalized. Using cookies in PHP isn't hard at all, and you should be able to use them without any difficulty.

Before actively using cookies in your website, you must check whether the visitor has enabled them in their browser. If they don't have cookies enabled, you must either redirect to a non-cookies version of your website, or you can make sure your website also works without cookies.

You can download a sample script at, where cookies are used in a (somewhat) practical way. In this example, there is a logging module, called log.php and a display module, called history.php. Basically, you include the log.php in other PHP pages, and then you can view history.php to lookup all the pages you have viewed and how often. The example uses arrays, and stores them in cookies.

The examples in this article can be downloaded at

If you have a really unique practical way of using cookies, please let me know at dennis [AT] nocertainty [DOT] com. I'd really like to hear about interesting ways of using cookies.

« Previous: Storing Arrays

One Response to “PHP and Cookies; a good mix!”

  1. Herojit Says:

    This site is very helpful to me.
    I expect more examples about session and cookies from this site.
    Thanks a lot.

Leave a Reply

About the author
Dennis Pallett is the main contributor to PHPit. He owns several websites, including ASPit and Chill2Music. He is currently still studying.
Article Index
  1. Introduction
  2. Using Cookies
  3. Checking if cookies are enabled
  4. Storing Arrays
  5. In Conclusion...
Bookmark Article
Download Article
Download this article as a PDF file