Home >> FAQs/Tutorials >> PHP Script Tutorials and Tips >> Index

PHP Script Tips - Understanding and Managing Cookies

By: FYICenter.com

Part:   1  2  3  4  5   6  7 

(Continued from previous part...)

Open your IE browser to visit this page: http://localhost/setting_persistent_cookies.php. You will see:

2 temporary cookies were delivered.
2 consistent cookies were delivered.
Did not received any cookie named as LoginName.
0 cookies received.

Now go to \Documents and Settings\$user\Cookies directory and open the cookie file, $user@localhost.txt. You will see:

CouponNumber
07470433
localhost/
1024
3084847744
29787636
2404950512
29786228
*
CouponValue
100.00
localhost/
1024
3084847744
29787636
2405150512
29786228
*

How Does FireFox Manage Cookies?

FireFox browser allows you to delete old cookies, and gives you options to keep persistent cookies in cookie files until they reach their expiration time. The following tutorial shows you how to manage cookies in FireFox:

  • Run FireFox
  • Go to Tools/Options
  • Click Privacy and then Cookies
  • Click the Clear button to delete all old cookies
  • Change the Keep Cookies option to "until they expire" to allow persistent cookies to be store a cookie file.

In Which Does File FireFox Store Persistent Cookies?

If you change FireFox to keep cookies "until they expire", FireFox will store persistent cookies from all Web servers in a single file at: \Documents and Settings\$user\Application Data\Mozilla \Firefox\Profiles\xby7vgys.default\cookie.txt.

Open your FireFox browser to visit this page: http://localhost/setting_persistent_cookies.php. Then open FireFox cookie file. You will see:

# HTTP Cookie File
# http://www.netscape.com/newsref/std/cookie_spec.html
# This is a generated file!  Do not edit.
# To delete cookies, use the Cookie Manager.

localhost   FALSE   /   FALSE   1149219379   CouponValue    100.00
localhost   FALSE   /   FALSE   1149219379   CouponNumber   07470433
......

How Many Cookies Can You Set?

How many cookies can you set in your PHP page? The answer is depending what is the Web browser your visitor is using. Each browser has its own limit:

  • Internet Explorere (IE): 20
  • Mozilla FireFox: 50

If you want to test this limit, copy this sample script, how_many_cookies.php, to your Web server:

<?php
  $count = count($_COOKIE);
  $name = "Cookie_".($count+1);
  $value = "FYICenter.com";
  setcookie($name, $value);
  print("<pre>\n"); 
  print("One cookies were added.\n"); 
  print("$count cookies received.\n");
  foreach ($_COOKIE as $name => $value) {
     print "  $name = $value\n";
  }
  print("</pre>\n"); 
?>

Open your browser to this page for first time, you will see:

One cookies were added.
0 cookies received.

(Continued on next part...)

Part:   1  2  3  4  5   6  7 


Selected Developer Jobs:

More...