PHP Cookies


A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values. For Firefox, you can check the cookies via
Tools  Options  Privacy

How to Create a Cookie?
The setcookie function is used to set a cookie. The setcookie function must appear before the <html> tag.

setcookie( name, value, expire, path, domain );

The example creates a cookie storing the customer name and the cookie expires after six minutes, 360 seconds. The time function returns the current time as a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).
 <?php
  $name  = "";
  $value = "";
  setcookie( $name, $value, time( )+ );
 ?>

 <html><body>
 <?php
  echo "Customer $value written to cookie";
 ?>
 </body></html>