I’m trying to use this php to clear out the session variables and return to the index page. However it’s not clearing them out. Any ideas?
logout.php
<?php
session_start();
unset($_SESSION['user_id']);
unset($_SESSION['username']);
session_destroy();
header("Location: http://aaronhaas.com/pitchshark6/index.php?vid_id=1");
?>
then in my navigation I’m using this code to either display their username and a logout link to logout.php or if they are not logged in display a sign in link.
<?php
// if logged in
if (isset($_SESSION['user_id']))
{
// display
echo "<a href='#'>".$_SESSION['username']."</a> ";
echo "<a href='scripts/logout.php'>Log Out</a> ";
}
// if not logged in
else
{ // display login link
echo "<a href='login.php'>Sign In</a>";
}
?>
here is my super simple login script
$username = $_POST['username'];
$password = $_POST['password'];
//Check if the username or password boxes were not filled in
if(!$username || !$password){
//if not display an error message
echo "<center>You need to fill in a <b>Username</b> and a <b>Password</b>!</center>";
}else{
// find user by username and password - working
$userQuery = 'SELECT * FROM users WHERE user_name ='.'"'. $username.'" AND password='.'"'. $password.'"' ;
$users = mysql_query($userQuery);
$user = mysql_fetch_array($users);
$_SESSION['user_id'] = $user['user_id'];
$_SESSION['username'] = $user['username'];
header("Location: http://aaronhaas.com/pitchshark6/index.php?vid_id=1");
}