开发者

Extending cookie expiration dates in PHP

开发者 https://www.devze.com 2023-04-06 17:58 出处:网络
When I look at the cookies for my site in Google Chrome, I see PHPSESSID,__utma, __utmb, __utmc, and __utmz. I don\'t understand what these cookies mean, except for maybe PHPSESSID, 开发者_JS百科which

When I look at the cookies for my site in Google Chrome, I see PHPSESSID,__utma, __utmb, __utmc, and __utmz. I don't understand what these cookies mean, except for maybe PHPSESSID, 开发者_JS百科which I assume is the user's login session. Some expire "When I close my browser" and other expire at some future date. Is there a way I could make them all expire in 2 years for example?

I'm trying to make it so the user stays logged in after closing the browser.


__utma, __utmb, __utmc, __utmz are cookies set by Google Analytics, not your site's code.

To extend the PHPSESSID cookie, your PHP session cookie, modify the setting in php.ini:

; some long value in seconds (1 year)
session.gc_maxlifetime = 31536000
session.cookie_lifetime = 31536000

For cookies you yourself have set in code via setcookie() (none of which are listed among your list), pass the third parameter as a value in seconds:

// Two year cookie (86400 secs per day for 2 years)
setcookie('name', 'cookievalue', time() + 86400 * 365 * 2);


These are cookies from Google analytics to track you. You can read more about it here

Only times user gets logout from your website is when session or cookies expries. If they expire time is 0, they expires when browser closes


you need to find the code that sets the coockies and add the appropriate expire time

setcookie ("TestCookie", "", time() + 3600); //expires after 1 hour
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号