Connecting Tech Pros Worldwide Help | Site Map

Cookie is in a cache?

p2
Guest
 
Posts: n/a
#1: Aug 23 '05
Hi,

I'm setting a cookie with setcookie, and as long as I'm not closing the
browser - the cookie is kept and passed to the next page.

But as soon as I leave the site or close the browser, the cookie is
gone, ans there is nothing in $_COOKIE dor the next time.

The cookie is not shown in the cookies folder.

This is the command I use:
setcookie ('lang', $lang, 77000);

Thanks,

Ramon
Guest
 
Posts: n/a
#2: Aug 23 '05

re: Cookie is in a cache?


Well you actually have to read the cookie. Because the cookie is stored
by the clients browser. Not by the server. If you need a more
suffisticated explanation drop another comment in here, but I'm sure you
can find the function in the php.net docs.

Cheers,

D

p2 wrote:[color=blue]
> Hi,
>
> I'm setting a cookie with setcookie, and as long as I'm not closing the
> browser - the cookie is kept and passed to the next page.
>
> But as soon as I leave the site or close the browser, the cookie is
> gone, ans there is nothing in $_COOKIE dor the next time.
>
> The cookie is not shown in the cookies folder.
>
> This is the command I use:
> setcookie ('lang', $lang, 77000);
>
> Thanks,
>[/color]
p2
Guest
 
Posts: n/a
#3: Aug 23 '05

re: Cookie is in a cache?


Thanks.

I know that... (that's why I wrote "The cookie is not shown in the
cookies folder." reffering to the local folder)

What I did to debug is to setcookie of a rendom number, and right after
that I placed print_r ($_COOKIE).

I can refresh as much as I want and as long as I'm not closing the
browser I see the cookie passed.

However when closing the browser or leaving the site and than returning
will result with empty $_COOKIE (until I refresh).

thanks again

Ramon
Guest
 
Posts: n/a
#4: Aug 23 '05

re: Cookie is in a cache?


Which browser are you using?

p2 wrote:[color=blue]
> Thanks.
>
> I know that... (that's why I wrote "The cookie is not shown in the
> cookies folder." reffering to the local folder)
>
> What I did to debug is to setcookie of a rendom number, and right after
> that I placed print_r ($_COOKIE).
>
> I can refresh as much as I want and as long as I'm not closing the
> browser I see the cookie passed.
>
> However when closing the browser or leaving the site and than returning
> will result with empty $_COOKIE (until I refresh).
>
> thanks again
>[/color]
p2
Guest
 
Posts: n/a
#5: Aug 23 '05

re: Cookie is in a cache?


It's the same for FF and IE.

I think it's something in the php.ini on the local machine because when
publishing the page to a server on the internet, it's fine.

The problem is that I don't have access to the php.ini on the other
machine.

Thanks,

Ramon
Guest
 
Posts: n/a
#6: Aug 23 '05

re: Cookie is in a cache?


try this at the top of the page

header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);


p2 wrote:[color=blue]
> It's the same for FF and IE.
>
> I think it's something in the php.ini on the local machine because when
> publishing the page to a server on the internet, it's fine.
>
> The problem is that I don't have access to the php.ini on the other
> machine.
>
> Thanks,
>[/color]
Alvaro G Vicario
Guest
 
Posts: n/a
#7: Aug 23 '05

re: Cookie is in a cache?


*** p2 wrote/escribió (22 Aug 2005 17:36:31 -0700):[color=blue]
> setcookie ('lang', $lang, 77000);[/color]

From manual:


usage:

bool setcookie ( string name [, string value [, int expire [,
string path [, string domain [, bool secure]]]]] )

expire:

The time the cookie expires. This is a Unix timestamp so is in number of
seconds since the epoch. In otherwords, you'll most likely set this with
the time() function plus the number of seconds before you want it to
expire. Or you might use mktime().

time()+60*60*24*30 will set the cookie to expire in 30 days. If not set,
the cookie will expire at the end of the session (when the browser closes).


Since 77000 is less than a day, you're telling the browser that cookie
should expire somewhere in 1970 (the epoch).

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
p2
Guest
 
Posts: n/a
#8: Aug 23 '05

re: Cookie is in a cache?


You'll never know how much I thank you!

Alvaro G Vicario wrote:[color=blue]
> *** p2 wrote/escribió (22 Aug 2005 17:36:31 -0700):[color=green]
> > setcookie ('lang', $lang, 77000);[/color]
>
> From manual:
>
>
> usage:
>
> bool setcookie ( string name [, string value [, int expire [,
> string path [, string domain [, bool secure]]]]] )
>
> expire:
>
> The time the cookie expires. This is a Unix timestamp so is in number of
> seconds since the epoch. In otherwords, you'll most likely set this with
> the time() function plus the number of seconds before you want it to
> expire. Or you might use mktime().
>
> time()+60*60*24*30 will set the cookie to expire in 30 days. If not set,
> the cookie will expire at the end of the session (when the browser closes).
>
>
> Since 77000 is less than a day, you're telling the browser that cookie
> should expire somewhere in 1970 (the epoch).
>
> --
> -- Álvaro G. Vicario - Burgos, Spain
> -- http://bits.demogracia.com - Mi sitio sobre programación web
> -- Don't e-mail me your questions, post them to the group
> --[/color]

Closed Thread