Call undefined session_unregister () function when trying to output

track this error when logging out. thanks

function doLogout() { if(isset($_SESSION['username'])); { unset($_SESSION['username']); session_unregister('username'); } header('Location: logme.php'); exit; } 
+6
source share
4 answers

This feature has been disabled since PHP 5.3.0 and removed since PHP 5.4.0.

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

session_unregister not available with php 5.4, so you can remove the function call.

With an equal call, there will only be unset - so you can replace

 session_unregister('username'); 

with

 unset($_SESSION['username']); 

if you do not want to rewrite all your code, you can write your own session_unregister function

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

This function does not do the same, but in most cases it’s enough

+3
source

According to the PHP manual, the session_unregister() function was DEPRECATED ...

PHP manual

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

+2
source

If you are using PHP> = 5.4

This function has been DEPRECATED since PHP 5.3.0 and removed from PHP 5.4.0. http://php.net/manual/en/function.session-unregister.php

+1
source

Source: https://habr.com/ru/post/969572/


All Articles