Joseph Grogan
New Member
Hi all....
I have code here that allows me to login to an area of a site but loggin out you have to close down the browser and i dont want that i want a logout page.
Here is the code i using to log in
This works fine its just logging out wont work.. I have a page called logout.php
But this does not remove any details as when i go back to the login page all my information is still there...
I have code here that allows me to login to an area of a site but loggin out you have to close down the browser and i dont want that i want a logout page.
Here is the code i using to log in
PHP:
<?php
session_start();
require_once('***login page details****');
require_once('***Where Pear MDB2 is located****');;
if (empty($_SESSION['user_id'])) {
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
header('WWW-Authenticate: Basic realm="Member Area"');
header("HTTP/1.0 401 Unauthorized");
echo "You must enter in a username and password combination!";
exit;
}
$connection = MDB2::connect("mysql://$db_username:$db_password@$db_host/$db_database");
if (MDB2::isError($connection)){
die ("Could not connect to the database: <br />". MDB2::errorMessage($connection));
}
$username = mysql_real_escape_string($_SERVER['PHP_AUTH_USER']);
$password = mysql_real_escape_string($_SERVER['PHP_AUTH_PW']);
$query = "SELECT `user_id`, `username` FROM `users` WHERE
`username`='".$username."' AND `password`=MD5('".$password."') LIMIT 1";
$result = $connection->query($query);
if(!($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC))) {
header('WWW-Authenticate: Basic realm="Member Area"');
header("HTTP/1.0 401 Unauthorized");
echo "Your username and password combination was incorrect!";
exit;
}
$_SESSION['user_id'] = $row['user_id'];
$_SESSION['username'] = $row['username'];
}
PHP:
session_start();
session_destroy();
$_SESSION = array();
echo "Thank you for loggin out: ";
But this does not remove any details as when i go back to the login page all my information is still there...