...

View Full Version : Problem with logout page



jojohummer
03-06-2010, 01:35 PM
Hello there,
I am working on a website that is fairly easy. In it i have a login page witch is working perfectly. but the only little problem is that I tried creating a logout page but it doesn't want to work. I saw in other forums that there are differant ways to do a lougout script.
This is the script of the login page :

<?php

/* Because the authentication prompt needs to be invoked twice,
embed it within a function.
*/
function authenticate_user() {
header('WWW-Authenticate: Basic realm="Tickets"');
header("HTTP/1.0 401 Unauthorized");
exit;
}
/* If $_SERVER['PHP_AUTH_USER'] is blank, the user has not yet been
prompted for the authentication information.
*/
if (!isset ($_SERVER['PHP_AUTH_USER'])) {
authenticate_user();
} else {
// Connect to the MySQL database
mysql_pconnect("....", "....", "....") or die("Can't connect to database server!");
mysql_select_db(".....") or die("Can't select database!");
// Create and execute the selection query.
$query = "SELECT username, pswd FROM userauth
WHERE username='$_SERVER[PHP_AUTH_USER]' AND
pswd='$_SERVER[PHP_AUTH_PW]'";
$result = mysql_query($query);
// If nothing was found, reprompt the user for the login information.
if (mysql_num_rows($result) == 0) {
authenticate_user();
} else {
echo "<center><h3>You are logged in as " . $_SERVER['PHP_AUTH_USER'] . "</h3></center>";
}
}
?>

Hope someone out there could help me with this little problem.
Thanks
Joris

masterofollies
03-06-2010, 04:26 PM
There is no log out in this script.

Creating one can be simple, this is a log out script which kills your session and logs you out, very simple and works. You can add onto it to build a thank you for logging out message and all.


<?
session_start();
session_destroy();
?>
You have successfully logged out.<br><br><br>
Return to <a href="index.html">Website</a>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum