Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should we destroy session in php?

Tags:

php

session

session_destroy() destroys session data but does not unset any of the global variables associated with session or unset the session cookie.

So why should we destroy session?

Can we destroy a session at the end of page each time the session starts in the beginning of that page giving the same functionality without destroying as well?

like image 428
user6181297 Avatar asked Mar 12 '23 14:03

user6181297


1 Answers

session_destroy() will delete the session file (if file storage is used). Otherwise the session file will reside on the server until the garbage collection deletes it. So, if you want to make sure that the stored session data is removed from the server you have to call session_destroy().

Do not call this on every page! Only after the user logs out and you do not need the stored information anymore.

like image 190
Markus Müller Avatar answered Mar 15 '23 23:03

Markus Müller