How do I create persistent sessions in PHP?

后端 未结 4 421
长发绾君心
长发绾君心 2020-11-29 03:56

I used session_start() to initiate a session in PHP, but when my browser closes, the session is gone.

How do I use PHP to create persistent sessions tha

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-29 04:38

    You can start your session without typing session_start() and you can start it with cookie like this

    setcookie('PHPSESSID','any id' , any time);
    

    this could be done because when you type session_start() and then try to look the cookie like this

    print_r($_COOKIE);
    

    then the outpout will be :

    Array ( [PHPSESSID] => c0voj7h0b4aesddkc17a6jk7c3 )
    

    just try it yourself

提交回复
热议问题