开发者

Session unset function not working

开发者 https://www.devze.com 2023-02-21 04:32 出处:网络
I have made this code(it is a part of my whole script) -- if(unset($_SESSION[\'USER_ID\'])) { $success_code_array[] = \'3111\';

I have made this code(it is a part of my whole script) --

if(unset($_SESSION['USER_ID']))
{
     $success_code_array[] = '3111';
     $_SESSION['POPUP_SUCCESS_CODE'] = $success_code_array;
     session_write_close();
     header("Location: ".$_SESIION['PATH']."");
   开发者_如何学Python  exit();
}
else
{
     $_SESSION['ERROR_CODE'] = '177';
     session_write_close();
     header("Location: ".$_SESSION['PATH']."error.php");
     exit();
}

And error I got --

Parse error: syntax error, unexpected T_UNSET in C:\xampp\htdocs\mysharepoint\1.1\res\scripts\php\functions\log_out.php on line 21

Can anyone tell me why I'm getting this error and what could be done to overcome this error?


unset is void, it doesn't return anything. If this is kind of logout script you probably can destroy the whole session as follows:

if(session_destroy()) { ...

Of course you should save $_SESSION['PATH'] somewhere for further usage before you destroy the session ...

EDIT:

Beware you have also a typo there. It doesn't cause the problem but may save you few minutes later:

if(unset($_SESSION['USER_ID']))
{
     $success_code_array[] = '3111';
     $_SESSION['POPUP_SUCCESS_CODE'] = $success_code_array;
     session_write_close();
     header("Location: ".$_SESIION['PATH'].""); // <-- $_SESIION instead of $_SESSION
     exit();
}


Don't unset session but destroy it. That's the proper way to unset it.


unset() returns nothing (void). http://de2.php.net/manual/en/function.unset.php

I'm not sure if the error comes from this but it doesn't make sence using it in an if-statement.

0

精彩评论

暂无评论...
验证码 换一张
取 消