Zend - The PHP Company




Cookies

Add Code


Setting cookies  

Type: code fragment
Added by: smog
Entered: 16/03/2000
Last modified: 07/12/2006
Rating: *** (22 votes)
Views: 21958
Simple script to use cookies.


<?
  
// By Jos� Afonso Santos aka smog
  // 
  // smog@kaotik.org
  // http://hero.kaotik.org/

  // Delete a cookie.
  
setCookie('name');

  
// Getting the current date
  
$hour date("H:i:s");
  
$year date("y");
  
$year++; // Adding one year to the current year
  
$day date("d-M-") . $year 
  $day_off_the_week 
date("l");
 
  
// Setting the validation of the cookie up to one year.
  
$validation $day_off_the_week ", " $day " " 
  
$hour " GMT";

  
// Set a cookie's value.
  
header("Set-Cookie: name=the-name-you-want;
  expires=
$validation; path=/");

  
// Create a cookie that only scripts in the
  // private directory can read.
  
header("Set-Cookie: country=the-country;
  expires=
$validation; path=/private/");

  
// After the cookies are set, you can access them
  // using normal PHP variables.
  
echo "<center>Hello <b>$name</b> !</center>";
?>


Usage Example




Rate This Script





Search



This Category All Categories