Reputation: 35
Was just wondering why my code isn't working here:
<?php
session_start();
if (isset($_SESSION)) {
session_unset();
session_destroy();
}
?>
I've tried printing out the result of echo isset($_SESSION) and it returns true, and my pages that require login are still allowing me to access them.
Upvotes: 0
Views: 1762
Reputation: 124
You must definitely define a variable as session
for example:
LOGIN
<?php
session_start();
if($_POST['username']){
$_SESSION['username'] =$_POST['username']; // session run
}
?>
LOGOUT
<?php
session_start();
if($_POST['LOGOUT']=='exit'){
@session_unset();
}
?>
You can also use unset($_SESSION['username']); instead of session_unset();
Upvotes: 2