SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Logging Out

Hybrid View

  1. #1
    SitePoint Guru godsfshrmn's Avatar
    Join Date
    Mar 2001
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Logging Out

    Hello all. I have modifed the article from here on user authentication to include cookies so the user does not have to log in each visit of the site. The problem is, I can't figure out how to let them logout. Here is the source code of the two files.

    auth.php (included in each file)
    PHP Code:
    <?
    session_start
    ();

    $uid = isset($_COOKIE['uid']) ? $_COOKIE['uid'] : $_SESSION['uid'];
    $pwd = isset($_COOKIE['pwd']) ? $_COOKIE['pwd'] : $_SESSION['pwd'];

    $_SESSION['uid'] = $uid;
    $_SESSION['pwd'] = $pwd;

    $sql "SELECT * FROM info WHERE charname = '$uid' AND pass = '$pwd'";
    $result mysql_query($sql);
            
    $r mysql_fetch_array($result); 
            
    $pre $r["premium"];

    if (!
    $result) {
        echo 
    "A database error occurred while checking your login details!";
        echo 
    mainFooter();
        exit;
    }

    ?>
    logout.php
    PHP Code:
    <?
        session_start
    ();
        
    session_unregister('uid'); 
        
    session_unregister('pwd');
        
    setcookie ("uid"""mktime(12,0,0,111990));
        
    setcookie ("pwd"""mktime(12,0,0,111990));
        
    session_destroy(); 
        unset(
    $uid); 
        unset(
    $pwd);

        
    header("Location: http://www.eqsig.com");
    ?>
    After the logout file redirects me to the homepage, it shows i am still logged in.
    s c r i p t s f o r y o u . n e t
    ScriptsForYou

  2. #2
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have not used session up to date but, my guess would be:
    PHP Code:
       unset($uid); 
        unset(
    $pwd);
    $uid="";
    $pwd=""

        
    header("Location: http://www.eqsig.com"); 
    </FONT>

    My guess would be that now you have an answer, if its wrong theres more change of some-one correcting me.

  3. #3
    SitePoint Guru godsfshrmn's Avatar
    Join Date
    Mar 2001
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think my problem is with the cookies. Logout worked before I added cookies. I think the cookies are not expiring.
    s c r i p t s f o r y o u . n e t
    ScriptsForYou

  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)
    Also, think about not using short tags

  5. #5
    SitePoint Guru godsfshrmn's Avatar
    Join Date
    Mar 2001
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whats a short tag?
    s c r i p t s f o r y o u . n e t
    ScriptsForYou

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Lincolnshire, UK
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <? is short
    <?php is full?

  7. #7
    SitePoint Addict
    Join Date
    Mar 2005
    Location
    India
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How are you setting (creating) your cookies?
    Please provide the code.

    May be you are taking more parameters (in the setcookie function) while you are setting up your cookies.
    Cookies must be deleted with the same parameters as they were set with.

  8. #8
    SitePoint Guru godsfshrmn's Avatar
    Join Date
    Mar 2001
    Posts
    671
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
            $cookie_life = time() + 31536000;
        setcookie('uid', $uid, $cookie_life);
        setcookie('pwd', $pwd, $cookie_life);

    ///i tried running this code also:
    <?
        session_start
    ();
        
    session_unregister('uid'); 
        
    session_unregister('pwd');
        
    $cookie_life time() - 315360000;
        
    setcookie ("uid"$uid$cookie_life);
        
    setcookie ("pwd"$pwd$cookie_life);
        
    session_destroy(); 
        unset(
    $uid); 
        unset(
    $pwd);

        
    header("Location: http://www.eqsig.com");
    ?>
    s c r i p t s f o r y o u . n e t
    ScriptsForYou


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
  •