IT Community - Software Programming, Web Development and Technical Support

Cookie Expiry

This is a discussion on Cookie Expiry within the PHP Programming forums, part of the Web Development category; Problem Short expiry cookies depend on users having their system clocks set correctly. Solution Don't depend on the users ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-18-2007, 01:28 AM
vijayanand vijayanand is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 293
vijayanand is on a distinguished road
Default 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','');
}
?>
__________________

J.Vijayanand
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Retrieve a Cookie Value? sundarraja PHP Programming 4 04-02-2008 07:00 AM
How to set time for cookie in ASP.NET? jeyaprakash.c ASP and ASP.NET Programming 9 01-16-2008 10:52 PM
What Is a Persistent Cookie? Sabari PHP Programming 19 09-21-2007 08:29 AM
How can I set a cookie in JSP? anbuchezhians Java Server Pages (JSP) 1 07-27-2007 03:02 AM
How do I set a cookie from JavaScript? oxygen HTML, CSS and Javascript Coding Techniques 1 07-26-2007 02:57 AM


All times are GMT -7. The time now is 03:10 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0