Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

cookie

General discussions related to php

Moderators: macek, egami, gesf

cookie

Postby Chip » Sun Jul 20, 2003 6:33 pm

i have a problem with cookies:
setcookie("name","value") keeps the cookie "on" forever...
but setcookie("name","value", time()+1000) should keep the cookie alive for 1000 seconds, right... the problem is that it doesn't in my case - it keeps it alive for just 20 seconds...
i guess that it is the difference between my time and the server's time... can this situation be avoided? i use that script for a counter, and if someone with a totally different time, or from another timezone visits, the counter would be unusefull
Chip
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Jul 20, 2003 6:27 pm

Re: cookie

Postby WiZARD » Tue Jul 22, 2003 12:10 am

maby in youre browser cookies is off?
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby Chip » Tue Jul 22, 2003 2:42 am

No, my browser works well with cookies. I found the problem - the difference between my time and the server's time. now, how do i set a cookie that "lasts forever" - i mean that does not expire after the browser is closed?
Chip
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Jul 20, 2003 6:27 pm

Postby WiZARD » Tue Jul 22, 2003 4:29 am

setcookie ("TestCookie", $value,time()+60*60*24*30); cookie to expire in 30 days. If not set, the cookie will expire at the end of the session (when the browser closes).
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

Postby Chip » Tue Jul 22, 2003 11:01 am

i know how to make it expire... though 30 days is a long time... I WANT IT TO BE AVAILABLE FOR EVER, even after 3 years... don't ask why... i just want to know...
Chip
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Jul 20, 2003 6:27 pm

Postby swirlee » Tue Jul 22, 2003 11:20 am

You can't make a cookie stay alive forever, and for good reason. Just pick a expiration date a long time in the future, and you'll be fine. Think of it this way: Even if you could make the cookie never expire, eventually it would be destroyed or forgotten when the user gets a new computer or reformats their hard drive or suffers a hard OS crash or runs a drive cleaning program.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Virtuoso » Tue Jul 22, 2003 11:29 am

dunno if this is possible, but whenever like the person visits the site, you could unset the cookie and reset it. and you could set the cookie to 1 year, you user is bound to visit your site within 1 year
here is a one year cookie:
Code: Select all
setcookie("cookie",$value, time()+(365*38400));
User avatar
Virtuoso
php-forum Active User
php-forum Active User
 
Posts: 268
Joined: Mon Jul 21, 2003 7:05 am


Return to PHP General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron