Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    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?


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •