I have just resorted to making a login page with sessions for my script, because HTTP Authentication won't work because of my web server.
Anyway, I seem to be logged in all the time, and when I use my logout page it says:
Code: Select all
PHP Warning: session_destroy(): Trying to destroy uninitialized session in D:\Webspace\wrightandshields.co.uk\wwwroot\PHPJayMail\index.php on line 89Code: Select all
//***LOGIN***
if ((isset($_SESSION['username'])) || (isset($_SESSION['password']))) { //If the username or password do not match
if (isset($_POST['login'])) {
if (($_POST['username'] == PJMUSER) && ($_POST['password'] == PJMPASS)) {
//Start the session and register the values
session_start();
$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];
} else {
$message = "<font color=\"red\">Sorry, your username and password did not match.<br>Please try again!</font><br>";
}
}
//Display the title image
echo "<img src=\"images/login.jpg\" alt=\"Login!\"><br>";
//Display the error message if there is one
if (isset($message)) {
echo $message;
}
//Start the login form/table
echo '<form action="index.php" action="post">';
echo '<table border="0">';
echo '<tr>';
echo '<td><b>Username: </b></td>';
echo '<td><input type="text" size="20" value="';
if (isset($_POST['username'])) {
echo $_POST['username'];
}
echo '"></td>';
echo '</tr>';
echo '<tr>';
echo '<td><b>Password: </b></td>';
echo '<td><input type="password" size="20"></td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2" align="center"><input type="submit" name="login" value="Login"></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
} else { //If the session is set run the rest of the script
//*********My logout script is here:
Code: Select all
//***LOGOUT***
if ($_GET['page'] == "logout") {
//if (isset($_SESSION['username'])) {
//Log the user out
$_SESSION = array(); //Destroy the variables in the $_SESSION array
session_destroy(); //Destroy the session itself
setcookie (session_name(), '', time()-300, '/', '', 0); //Destroy the cookie
//}
//Show the image header
echo '<img src="images/logout.jpg" alt="Logout!"><br><br>';
//Show the success message
echo 'You are now logged out.<br><br>';
}
//*********Thanks in advance.