当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - How to set a fixed time cookie in PHP?

问题描述:

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'));
分享给朋友:
您可能感兴趣的文章:
随机阅读: