Home » Php » php – call to undefined function session_unregister() when trying output

php – call to undefined function session_unregister() when trying output

Posted by: admin July 12, 2020 Leave a comment

Questions:

monitoring this error when logout.
thank you

function doLogout()
{
if(isset($_SESSION['username']));
{
unset($_SESSION['username']);
session_unregister('username');
}
header('Location: logme.php');
exit;
}
How to&Answers:
  1. omit ;
  2. from php.net session_unregister()

This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

function doLogout()
    {
    if(isset($_SESSION['username']))
    {
    unset($_SESSION['username']);       
    }
    header('Location: logme.php');
    exit;
    }

Answer:

session_unregister isn’t available since php 5.4, so you can remove the function call.

An equal call would be just unset – so you can replace

session_unregister('username');

with

unset($_SESSION['username']);

if you don’t want to rewrite your whole code, you can write your own session_unregister function

if (!function_exists('session_unregister')) {
    function session_unregister($var) { unset($_SESSION[$var]); }
}

This function doesn’t do the same, but is in most cases sufficient

Answer:

According to the PHP manual, session_unregister() function has been DEPRECATED …

PHP Manual

use unset($_SESSION["key"]); instead

Answer:

If you are using PHP >= 5.4

This function has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.
http://php.net/manual/en/function.session-unregister.php