snippet library logo
Amazon.com
in category
PHP / Cookies / Sessions / Another way to set a cookie
Snippet details
ID: 120
Viewed: 1806
Added: 2002-04-17
Version:
Sorry no demo

User Rated at: 3 Stars
Rate This:
Snippets in this catagory         
Show Printable Version
Another way to set a cookie in php. it also includes a date function for a time frame of a year.

General Details
Snippet uploaded by: snippet
Email : webmaster@snippetlibrary.com
Snippet By: smog

<!---Head--->
none

<!---Body--->


<?
  
// 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>"
?>




No Reviews to show


Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.


Subject:

Reviewed By:

Write a review:





Terms of Conditions
Powered By
Avian Hosting
© 2005 snippetlibrary.com All Rights Reserved.