PHP / Cookies / Sessions / Another way to set a cookie
Snippet details
ID: 120
Viewed: 1806
Added: 2002-04-17
Version:
Sorry no demo
Another way to set a cookie in php. it also includes a date function for a time frame of a year.
<!---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
