PHP - session_set_cookie_params(), lifetime doesn't work

匿名 (未验证) 提交于 2019-12-03 10:03:01

问题:

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

回答1:

Rewrite your code as

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


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!