问题描述:

I am using cookies to store user preferences. When users log in I want to get their preferences from the database and store them in cookies. I want to store the cookie to expire on a fixed date like this:

document.cookie = document.getElementById('user').value + '=' + preferences + '; expires=Fri, 31-Dec-2030 23:59:59 GMT; path=/; domain=.website.com';

As you can see the JavaScript method sets the cookie to expire on 31-Dec-2030 23:59:59 GMT. How can I do the same in PHP?

One more thing the way I am storing cookie sets the cookie name to user name and the preferences are not encrypted they are stored as plain text. They don't have any sensitive information though. Is it safe to use cookies this way?

网友答案:

Use php strtotime()

setcookie("cookie_name", "cookie_value", strtotime('2030-31-12 23:59:59 GMT'));
网友答案:

Use php time()

setcookie("cookiename", 'cookievalue', strtotime('2030-31-12 23:59:59 GMT'));
相关阅读:
Top