Reputation: 49
The problem is that i have the file "login.php" where i start a session
session_start();
$_SESSION['uname'] = $uname;
so according to this i am redirected to a file "main.php" which includes "header.php" where i have a button with a "href" to external file:
<a href="logout.php" action="includes/process.php" method="post" ><li>Logout</li></a>
This external file includes:
<?php
unset($_SESSION['uname']);
?>
But the real question in here is when i press this button and goes to "logout.php" and executes the code, why i can back to the previous main page ? And i forgot to tell that have an error:Undefined variable: _SESSION in C:\xampp\htdocs\rootFolder\logout.php on line 3
or if i use session_destroy: session_destroy(): Trying to destroy uninitialized session in C:\xampp\htdocs\rootFolder\logout.php on line 3
Upvotes: 0
Views: 123
Reputation: 2163
on external file "logout.php" you did not started session "session_start()".
Use this code in External "logout.php":
<?php
session_start();
unset($_SESSION['uname']);
?>
Upvotes: 0
Reputation: 4879
You have to use session_destroy()
instead of unset()
.
<?php
session_start();
session_destroy();
header("Location: login.php");
?>
And you have to start_session()
at the top of all your files.
Upvotes: 0