I have a login php which checks student name and password against a database. If both are correct, the student can open the page. Seems to work OK, lets me open the page if name and pw are in the database.
I put a nice little logout button on the page:
<?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/logout.inc.html.php';?>
That looks like this:
<form action="" method="post">
<div>
<input type="hidden" name="action" value="logout">
<input type="hidden" name="goto" value="/">
<input type="submit" value="Log out">
</div>
</form>
It works, inasmuch as , it takes me back to the homepage. However, if I click on the page I was logged into again, it opens without going to the login page first.
Is this some setting in php.ini?? What must I do to actually be logged out?
The whole access file is this:
<?php
function userIsLoggedIn1()
{
if (isset($_POST['action']) and $_POST['action'] == 'login')
{
if (!isset($_POST['name']) or $_POST['name'] == '' or
!isset($_POST['password']) or $_POST['password'] == '')
{
$GLOBALS['loginError'] = 'Please fill in both fields';
return FALSE;
}
$password = md5($_POST['password'] . 'allstudentsdb');
if (databaseContainsStudent1($_POST['name'], $password))
{
session_start();
$_SESSION['loggedIn'] = TRUE;
$_SESSION['name'] = $_POST['name'];
$_SESSION['password'] = $password;
return TRUE;
}
else
{
session_start();
unset($_SESSION['loggedIn']);
unset($_SESSION['name']);
unset($_SESSION['password']);
$GLOBALS['loginError'] =
'The specified name or password was incorrect.';
return FALSE;
}
}
if (isset($_POST['action']) and $_POST['action'] == 'logout')
{
session_start();
unset($_SESSION['loggedIn']);
unset($_SESSION['name']);
unset($_SESSION['password']);
header('Location: ' . $_POST['goto']);
exit();
}
session_start();
if (isset($_SESSION['loggedIn']))
{
return databaseContainsStudent1($_SESSION['name'], $_SESSION['password']);
}
}
function databaseContainsStudent1($name, $password)
{
include $_SERVER['DOCUMENT_ROOT'] . '/includes/studentdbReadfrom.inc.php';
try
{
$sql = 'SELECT COUNT(*) FROM 19BE
WHERE name = :name AND password = :password';
$s = $pdo->prepare($sql);
$s->bindValue(':name', $name);
$s->bindValue(':password', $password);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error searching for name.';
include $_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php';
exit();
}
$row = $s->fetch();
if ($row[0] > 0)
{
return TRUE;
}
else
{
return FALSE;
}
}
?>