Ok I have gone through various threads, etc and to the best of my ability I am using sessions for a logout screen from a system that I have built.
All well and good
The sessions are created.
When a user reaches the the logout page, the sessions are destroyed.
Whats the problem?
When a session is destroyed, the user is brought back to an index page (called index2.php)
However, if I press the back button, it appears that the session was not destroyed, and is reactivated.
On all pages, I have this page included (function.php)
It is basically a username/name or id catcher to make sure that whoever is veiwing is registered.
<?
if (($username) && ($password)){
$sql_check = "SELECT * from user where username=\"$username\" and password=\"$password\" LIMIT 1";
//execute sql query and get results
$sql_check_result = mysql_query($sql_check) or die("The username/password combination you entered is incorrect.");
$num_check = mysql_numrows($sql_check_result);
if ($num_check == "0"){
header("Location: index2.php");
}
else {
//format results by row
while ($row = mysql_fetch_array($sql_check_result))
{
$userID = $row["userid"];
$userName = $row["username"];
$userPass = $row["password"];
}
session_start();
$_SESSION['userID'] = $userID;
$_SESSION['userName'] = $userName;
$_SESSION['userPass'] = $userPass;
$id = $userID;
$dyn = "id=$userID";
}
}
else if ($id){
$sql_check = "SELECT * from user where userid=\"$id\" LIMIT 1";
//execute sql query and get results
$sql_check_result = mysql_query($sql_check) or die("That is an illegal id");
//format results by row
$num_check = mysql_numrows($sql_check_result);
if ($num_check == "0"){
header("Location: index2.php");
}
else {
while ($row = mysql_fetch_array($sql_check_result))
{
$userID = $row["userid"];
$userName = $row["username"];
$userPass = $row["password"];
}
session_start();
$_SESSION['userID'] = $userID;
$_SESSION['userName'] = $userName;
$_SESSION['userPass'] = $userPass;
$id = $userID;
$dyn = "id=$userID";
}
}
else if ((!$username) && (!$password)){
header("Location: index2.php");
}
else if (!$id){
header("Location: index2.php");
}
?>
whilst the logout page is
include("db.inc.php");
$sql_check = "SELECT * from user where userid=\"$id\" LIMIT 1";
//execute sql query and get results
$sql_check_result = mysql_query($sql_check) or die("That is an illegal id");
//format results by row
$num_check = mysql_numrows($sql_check_result);
while ($row = mysql_fetch_array($sql_check_result))
{
$userID = $row["userid"];
$userName = $row["username"];
$userPass = $row["password"];
}
session_start();
$_SESSION['userID'] = $userID;
$_SESSION['userName'] = $userName;
$_SESSION['userPass'] = $userPass;
unset($_SESSION['userID']);
unset($_SESSION['userName']);
unset($_SESSION['userPass']);
// kill session variables
$_SESSION = array(); // reset session array
session_destroy(); // destroy session.
header('Location: index2.php?id=');
Can someone explain to me, where I have gone wrong and maybe a pointer in the right direction?
Thanks in advance