I have created the following code (see below) using a book (that until now) has proved to be very good.
The problem that I'm having is that the logout doesn't work. According to th book, the variable LOGOUT should be set to 1 when the link is clicked on, causing the relavent part of the if statement to unset the session variable. This doesn't appear to be happening and the session is therefore never unsetting.
Any ideas?
<?php
if (isset($_POST['frm_username'])) {
if ($_POST['frm_username'] == 'abasel' and $_POST['frm_password'] == '12345') {
$_SESSION['authorized'] = TRUE;
}
}
if (isset($_REQUEST['logout'])) {
unset($_session['authorized']);
}
if (isset($_SESSION['authorized'])) {
?>
<p>Logged in</p>
<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?logout=1">Log Out</a></p>
<?php
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="310" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="104"><div align="center">Username</div></td>
<td width="206"><div align="center">
<input name="frm_username" type="text" id="frm_username">
</div></td>
</tr>
<tr>
<td><div align="center">Password</div></td>
<td><div align="center">
<input name="frm_password" type="password" id="frm_password" size="15" maxlength="8">
</div></td>
</tr>
<tr>
<td><div align="center">
<p> </p>
</div></td>
<td><p> </p></td>
</tr>
<tr>
<td><div align="center">
<p><a href="#" class="comment">Register a New Account</a></p>
<p><a href="#" class="comment">Forgotten Login Details</a></p>
</div></td>
<td valign="middle"><div align="center">
<input name="frm_login" type="submit" id="frm_login" value="Login">
</div></td>
</tr>
</table>
</form>
<?php