tags:

views:

51

answers:

2

Is it possible to read cookie expiration time with php ? When I print_r($_COOKIE) it outputs:

Array
(
    [PHPSESSID] => 0afef6bac83a7db8abd9f87b76838d7f
    [userId] => 1232
    [userEmail] => [email protected]
    [firstName] => user
    [lastName] => user
)

So I think $_COOKIE don't have the expiration time, is it possible with some other function?

+2  A: 

Only name and value are sent to the server so no other cookie data is available.

You can simply re-set the cookie if you want to extend its duration - that's just a few bytes more in the response so it doesn't matter at all.

ThiefMaster
so that means no way to get cookie expiration...
Ashish Rajan
No there isn't. What I personally do is save the expiration time in a database and have the cookie have some sort of identifier. Usually for saving login details the cookie is only the identifier (a long random one so it cannot be guessed). If the client (hypothetically) sent the expiration time, you shouldn't use it anyway, since it could have been tempered.
Artefacto
A: 

no, there is no way.
Browser uses cookie parameters (path, expiration etc) only to determine to send a cookie or not, but none of these parameters being sent back to server.

don't think of a cookie as of a $_SESSON array member but as an HTTP header. That's always helps.

Col. Shrapnel