SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Logging out.

  1. #1
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Logging out.

    PHP Code:
    <?

    if(!isset($_COOKIE['login']) && !isset($_COOKIE['login2'])){
                 die(
    'You are already logged out :)');

    }else{
        
        
    setcookie("login",""time()-24*3600);
        
    setcookie("login2",""time()-24*3600);
        
        }
    ?>

    <html>
    <title>Logging Out</title>
    <body>

    <?

      

       
    echo "<h1>Logged Out</h1>\n";
       echo 
    "You have successfully <b>logged out</b>. <a href = 'http://www.google.com'>Leave.</a>"


    ?>
    I SWEAR this script was just working-
    Whats happining with it, now?

  2. #2
    SitePoint Member xiberk's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does it need a session_start() call at the beginning of the script?

  3. #3
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added the session_start() to it, and it still isn't working.

    The login script is
    PHP Code:
    <?php
        session_start
    ();
        
    $db_user '$dbuser';
        
    $db_pass '$dbpass';
        
    $username $_POST['username'];
        
    $password $_POST['password'];


        
    $connection mysql_connect('localhost'$db_user$db_pass) or die(mysql_error());
        
    mysql_select_db('6081_1'$connection) or die(mysql_error());

        
    $query "SELECT * FROM users 
                WHERE username='
    $username' AND password='$password'";
                

        
    $result mysql_query($query$connection) or die('error making query');
        
    $affected_rows mysql_num_rows($result);


    if(
    $affected_rows == 1) {

            
    setcookie("login",$usernametime()+24*3600);
            
    setcookie("login2",$passwordtime()+24*3600);

            
            print 
    "You are now logged in as $username.  You can now go to the <a href='index.php'>forum</a>";
        
        }
        else {
            print 
    'That username and password combination was not valid';
            }
        
    ?>
    I suck with cookies/sessions, so bear with me.
    Last edited by Dylannn; Feb 25, 2005 at 23:41.

  4. #4
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please help

  5. #5
    get into it! bigduke's Avatar
    Join Date
    May 2004
    Location
    Australia
    Posts
    847
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure there is on output prior to the setcookie call? Even a space qualifies as an output.


Bookmarks

Posting Permissions

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