PHP and Cookies example
This example shows how to use cookies with PHP
<?php
/*
* PHP Cookie handling example
*/
// Setting a Cookie
//Calculate 15 days in the future
$days = 15;
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * $days + time();
setcookie('lastVisit', date("G:i - m/d/y"), $inTwoMonths);
?>
<?php
// Retrieving the Cookie and display the value
if(isset($_COOKIE['lastVisit'])){
$visit = $_COOKIE['lastVisit'];
echo "Your last visit was - ". $visit;
}
else {
echo "Cookie does not excist yet... Use setcookie";
}
?>
|
|
Description
Simple PHP and cookies example
Top