A cookie is created by using setCookie() function. This function takes 3 arguments:
– Name – The name of the cookie to be used to retrieve the cookie.
– Value – The value is persisted in the cookie. Usually, user names and last visit date / time are used
– Expiration – The date until which the cookie is alive. After the date the cookie will be expired. If the expiry date is not set, then the cookie is treated as a default cookie and will expire when the browser restarts.
//Set 60 days as the life time for the cookie.
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * 60 + time();
setcookie('lastVisit', date("G:i - m/d/y"), $inTwoMonths);
Posted in: PHP