View Single Post
  #18 (permalink)  
Old 12-18-2007, 06:23 AM
Sabari Sabari is offline
D-Web Genius
 
Join Date: Jul 2007
Posts: 1,008
Sabari is on a distinguished road
Default Re: PHP Tips and Tricks

Cookie Expiry

Problem
Short expiry cookies depend on users having their system clocks set correctly.

Solution
Don't depend on the users having their clocks set right. Embed the timeout based on your server's
clock in the cookie.


<?php
$value = time()+3600 . ':' . $variable;
SetCookie('Cookie_Name',$value);
?>
Then when you receive the cookie, decode it and determine if it is still valid.


<?php
list($ts,$variable) = explode(':',$Cookie_Name,2);
if($ts < time()) {
...
} else {
SetCookie('Cookie_Name','');
}
?>
__________________
Thanks & Regards
Sabari...
Reply With Quote