Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 23rd, 2005, 01:45 AM
p2
Guest
 
Posts: n/a
Default Cookie is in a cache?

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,

  #2  
Old August 23rd, 2005, 01:55 AM
Ramon
Guest
 
Posts: n/a
Default 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]
  #3  
Old August 23rd, 2005, 05:25 AM
p2
Guest
 
Posts: n/a
Default 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

  #4  
Old August 23rd, 2005, 05:25 AM
Ramon
Guest
 
Posts: n/a
Default 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]
  #5  
Old August 23rd, 2005, 05:45 AM
p2
Guest
 
Posts: n/a
Default 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,

  #6  
Old August 23rd, 2005, 05:55 AM
Ramon
Guest
 
Posts: n/a
Default 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]
  #7  
Old August 23rd, 2005, 08:45 AM
Alvaro G Vicario
Guest
 
Posts: n/a
Default 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
--
  #8  
Old August 23rd, 2005, 07:35 PM
p2
Guest
 
Posts: n/a
Default 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]

 

Bookmarks

Thread Tools

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

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

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles