简体   繁体   中英

PHP - session_set_cookie_params(), lifetime doesn't work

As first, I know a lot questions are like mine, but I really don't know what I'm doing wrong...

As you might've guessed, I've a PHP script involving sessions. Everything works like a charm, except setting the lifetime of my session.

I want to keep the session active for two weeks, but instead my (Chrome) browser says it's set to xpire after the browsing session (and it does). My PHP script:

session_name('DSWLogin');
// Naming the session

session_set_cookie_params(2*7*24*60*60);
// Making the cookie live for 2 weeks

session_start();
// Starting the session

It really doesn't work.

Thanks in advance,

Isaiah

Rewrite your code as

session_start();
setcookie(session_name('DSWLogin'),session_id(),time()+2*7*24*60*60);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM