简体   繁体   中英

Can i use session_start() at the start of every page i.e in the header file of my website

I know if session is not destroyed at the end of some specific task then it will retain its values and could create problems next when you use it. But when you say destroying a session then does it mean ending the session like this

session_end()

or it means that you have to unset some specific session which u have set before by doing this.

unset($_SESSION['id'] )

etc. And if i start a session at the top of every page and do not set it by $_SESSION['id'] etc then could that create problem for me. If yes then why i haven't got proper answer to this anywhere.

Here is how you destroy a session:

session_destroy();

There is no such thing as session_end() in PHP.

To empty a specific session variable, you generally do the following:

$_SESSION['id'] = '';

If you start a new session on top of every page using session_start it will just make sure the session is setup would it not be active for any reason (destroyed or never started).

It's untrue that there would be no documentation, actually, the web is full with articles and tutorials on session management. I myself used the following that helped me a lot to setup my login system of my web app: https://www.owasp.org/index.php/Session_Management .

I also suggest you have a read through all the functions that PHP specifically has to offer starting here: http://www.php.net/manual/en/features.sessions.php .

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