Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing session_unregister with unset()

Tags:

php

session

I'm moving a legacy system which I didn't create from one server (php 5.2) to a newer one (php 5.3) and a lot of the system uses session_unregister. I appreciate this is now deprecated in 5.3 so should I go ahead and replace all cases with unset($_SESSION['myVar']) or will this cause something to break?

Even better, is there an alternative that achieves the same function that I require, if unset() isn't the correct one

like image 209
Andy Avatar asked Jul 19 '12 14:07

Andy


People also ask

How to unset all session in php?

Destroying a PHP Session A PHP session can be destroyed by session_destroy() function. This function does not need any argument and a single call can destroy all the session variables. If you want to destroy a single session variable then you can use unset() function to unset a session variable.

What does session_ unset do in php?

session_unset() function: It deletes only the variables from session and session still exists. Only data is truncated. Example 1: This example saving the session by using session. php file.


1 Answers

You can unset specific session vars using unset($_SESSION['yourvar']);, but mind this part from the manual:

Do NOT unset the whole $_SESSION with unset($_SESSION) as this will disable the registering of session variables through the $_SESSION superglobal.

(from: http://php.net/manual/en/function.session-unset.php )

like image 72
Nanne Avatar answered Oct 18 '22 16:10

Nanne