Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetCookie Expire Time

Status
Not open for further replies.

alsaffar

Programmer
Joined
Oct 25, 2001
Messages
165
Location
KW
Hi everybody,

Subject: Setcookie expiration time.

Goal: To expire the cookie after 15 minutes (900 seconds) from setting.

Problem Description:
- When I set the expire parameter to time()+900, its taking the server timestamp where its in my case (time in GMT + 900).

(i.e. timestamp is 09:00AM GMT + 900 seconds -> expire at 09:15AM).

- If the user who is surfing my site is living in a country which its time is GMT+2, the cookie will not set (as I'm testing!) since the expiration time is in the past.

(i.e. User current loacl time is 09:00AM GMT + 2 -> 11:00AM) and the expire time of the cookie is 09:15AM as its returned from the setcookie function, which is in the past with respect to the user's browser local time.

Question:
- How can I overcome this problem? Since the user that surfing my site can be in any country in the world with its time is GMT+(X)hours, not necssary having the same server time. How can I set the cookie to the user's local time not the server time?


Please help my guys Im stucked ;)
 
Have you demonstrated this problem, or are you expecting this problem?

Cookie headers, like all HTTP headers, use GMT for all dates and times. This is in accordance with the Netscape cookie spec:
For example, running this code:

Code:
<?php
setcookie ('foo', 'bar', time()+300);
?>

on a server in U.S. Central time (Z - 5:00) at 2003-08-11 10:14:35 U.S. Central Time will get an HTTP cookie header which reads:

Set-Cookie: foo=bar; expires=Mon, 11-Aug-03 15:14:35 GMT

(this is the actual header as set by the above PHP code, picked up from my server using telnet)

So long as the date, time, and time zone are correctly set on your server, everything will work, regardless of the time zone of the server or client.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top