keep user logged in when he visit the same page again?

后端 未结 4 1013
余生分开走
余生分开走 2021-02-06 14:47

currently im using session to log in the user. but when i close the browser and open it again i have to log in again. how do you keeo the user logged in in lets say 2 weeks.

4条回答
  •  时光取名叫无心
    2021-02-06 15:02

    Read this: http://www.php.net/manual/en/session.configuration.php

    The setting that you need is session.cookie_lifetime. Session cookies (eg ones that do not have a lifetime) are deleted when the browser is closed. If you want the sessions to stay alive for longer, set that setting in php.ini, httpd.conf, or .htaccess. Possibly even with ini_set

    Edit: Actually you can use this function:

    session_set_cookie_params (86400*30);
    session_start()
    

    86400*30 is 30 days.

    See here: http://www.php.net/manual/en/function.session-set-cookie-params.php

提交回复
热议问题