Roman
Roman

Reputation: 3749

PHP getting expiring time of a cookie

Can I get the expiring time of a cookie which is already set? For example, I have set a cookie:

setcookie("test_cookie","some value", time()+3600*24*30);

Now can i get the time when the test_cookie is expiring? One option could be that when i set the test_cookie, i can set the expiring time in another cookie, but i'm wondering if there's alternative, better way without setting other cookie?

Thanks.

Upvotes: 3

Views: 343

Answers (3)

mymotherland
mymotherland

Reputation: 8228

Check this link How to get cookie's expire time

cookie expiration date can be set in another cookie.This cookie can then be read later to get the expiration date

Upvotes: 0

Brice Favre
Brice Favre

Reputation: 1527

There's no way to get the expiry time because the browser doesn't send it. So the olny way is to store the time somewhere in another cookie or in session maybe.

Upvotes: 1

Michael Wright
Michael Wright

Reputation: 591

Setting it in another cookie is the best method, that or simply appending it to the end of the data you're storing with a delimeter such as #.

Upvotes: 2

Related Questions