Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does die() end your session in PHP?

Tags:

php

If I execute:

die();

Will it also effectively call

session_write_close();

Because die stops the entire process?

like image 828
coderama Avatar asked Feb 14 '13 07:02

coderama


1 Answers

No. As you can see on the PHP page: http://www.php.net/manual/en/function.exit.php (because die is equivalent to exit)

Shutdown functions and object destructors will always be executed even if exit is called.

BUT, session_write_close is NOT a shutdown function. It will not run if you "die". I suggest you look into session_register_shutdown. This will register session_write_close() as a shutdown function and in this case, it will run on "die".

More Info: http://www.php.net/manual/en/function.session-register-shutdown.php

like image 78
Sites Done Right Avatar answered Oct 20 '22 15:10

Sites Done Right