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
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.
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.
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 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With