Forum Moderators: coopster

Message Too Old, No Replies

PHP Cookie Information

         

too much information

10:56 pm on Jun 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This seems like a simple problem, but I can't find the answer.

How do I read the expiration time for a cookie? I understand that reading the value of a cookie is just $HTTP_COOKIE_VARS["CookieName"] but is there a way to read when it expires?

What I'm trying to do is make a login with a "remember me" option. So if you choose "remember me" the cookie is permanent, but if not it expires an hour after you are done with the admin section of the site.

So I need to keep updating the cookie to expire after an hour, but only if it is set to expire less than an hour from "now". (if that makes any sence at all)

jatar_k

1:29 am on Jun 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try doing this

echo '<pre>';
print_r($_COOKIE);
echo '</pre>';

that will dump all the data from the cookie in a readable format and you can see what's there

also, $HTTP_COOKIE_VARS is deprecated so just use $_COOKIE instead

too much information

1:56 am on Jun 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$HTTP_COOKIE_VARS is deprecated so just use $_COOKIE instead

I'm glad you told me that, I thought it was the other way around!

So I tried printing out the cookie but it is just the text data either way I set it. I was just hoping for a quick way to check the expiration.

I guess the other thing I could do would be to use a session cookie instead for people that don't want to be logged in permanently.

Tastatura

3:16 am on Jun 17, 2007 (gmt 0)

10+ Year Member



are you actually setting the cookie expiration time? if so how (you can show the code just use example.com instead your domain)?

Habtom

5:17 am on Jun 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> So I need to keep updating the cookie to expire after an hour, but only if it is set to expire less than an hour from "now".

setcookie ("CookieName", "", time() + 3600);

But I don't know if there is a way to find out how much time is left in the cookie itself. You might create parallely running script in the server to let you know how much is left.

Habtom

too much information

5:50 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's the trick, finding out how much time is left on the cookie. If I use a session cookie for temporary logins that would solve the problem, but I was hoping to learn a new trick.

vincevincevince

6:09 am on Jun 18, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think that information is available, even using apache_request_headers() you only get to see e.g. [Cookie] => session=377a93bcd27c849b216eba69760c5526

The only way around it which I can see is to set two cookies, one of which just contains the value of time()...

You can then check by if ($_COOKIE[mycookie_time]<(time()-3600))