Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-06-2010, 12:35 PM   PM User | #1
jojohummer
New to the CF scene

 
Join Date: Sep 2009
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
jojohummer is an unknown quantity at this point
Problem with logout page

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 Code:
<?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
jojohummer is offline   Reply With Quote
Old 03-06-2010, 03:26 PM   PM User | #2
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
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.

PHP Code:
<?
session_start
();
session_destroy();
?>
You have successfully logged out.<br><br><br>
Return to <a href="index.html">Website</a>
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Reply

Bookmarks

Tags
login, logout, mysql, php, user

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:58 PM.


Advertisement
Log in to turn off these ads.