I create a file logout.php and calling it by
<a href='logout.php'>log out</a>
but the sessions are not destory or unset. Help me the logout.php file is given below
<?php session_start();
if(isset($_SESSION['user_id']) | isset($_SESSION['mem_id'])|
isset($_SESSION['fname']) | isset($_SESSION['lname'])) {
$_SESSION=array();
unset($_SESSION['user_id']);
unset($_SESSION['mem_id']);
unset($_SESSION['fname']);
if(isset($_COOKIE[session_name()])) {
setcookie(session_name(), '' , time()-3600);
}
session_destroy();
}
header("location:index.php");
?>
In my login file i genrate three session variable they are
$_SESSION['user_id'])
$_SESSION['mem_id'])
$_SESSION['fname'])
Help me to destroy this session variable
You don’t do
$_SESSION=array();, the variable already exists and is an array, you don’t declare as one again.You also need to use
||for OR. a single pipe|is a bitwise operator and not what you want.One thing you can do to debug is have it
echosomething inside theifstatement. If it does echo it to the screen, you know it go into that if statement. If it didn’t, you know it did not. Then you can begin to figure out if the conditions for the if statement are met or not to find what’s wrong.