# Php login script - sessions problem

**URL:** <https://forum.kirupa.com/t/php-login-script-sessions-problem/143363>\
**Category:** Uncategorized\
**Created:** [April 5, 2005, 1:22pm UTC](https://forum.kirupa.com/t/php-login-script-sessions-problem/143363 "2005-04-05T13:22:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sinus\_](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sinus_/32/417_2.png) [@sinus\_](https://forum.kirupa.com/u/sinus_)\
**Post date:** [April 5, 2005, 1:22pm UTC](https://forum.kirupa.com/t/php-login-script-sessions-problem/143363/1 "2005-04-05T13:22:40Z")

</div>

hello,

i made a login script. the problem is that when i click Logout (see code below - logout.php) then press Back button on the browser, i can still see the restricted page…

here are the codes:

**//\_checklogin.php**

```auto
<?php
session_start();
**//_checklogin.php**

include "_functions.inc.php";

$_SESSION['userok'] = checkuser($_SESSION['username'], $_SESSION['password']);

if (!$_SESSION['userok'])
{
	$_SESSION['username'] = $_POST['username'];
	$_SESSION['password'] = $_POST['password'];
	$_SESSION['userok'] = checkuser($_POST['username'],$_POST['password']);

	$_SESSION['user_status'] = $_SESSION['userok'][3];
	$_SESSION['fname'] = $_SESSION['userok'][1];
	$_SESSION['lname'] = $_SESSION['userok'][2];
	//$_SESSION['login'] = "ok";

	if(!$_SESSION['userok'])	
	{
		//echo "please login";
		header('Location: loginForm.php');
	}
}

/*
 * checkuser()
 * returns an array if username is found with correct password
 $query_data[] => username, fname, lname, status
*/
function checkuser($username,$password)
{
	global $database, $user_table;
	$link_id = db_connect($database);
	$query = "SELECT username, fname, lname, status FROM $user_table WHERE username = '$username' AND password = '$password'";
	$result = mysql_query($query);
	if (!($result)) {
		sqlError();
	}
	else {
		$query_data = mysql_fetch_row($result);
		return $query_data;
	}
}

?>

```

**\_logout.php**

```auto
<?php
session_start();
// Unset all of the session variables.
$_SESSION = array();
// Finally, destroy the session.
session_destroy();
header('Location: index.php');
?>

```

any help would be appreciated… .🙂 thanks guys
