Setting and destroying a cookie in simple login script

Discussion in 'PHP' started by lruneh, Dec 2, 2008.

  1. #1
    Hi all,

    I have a very simple login script, which in spite of its simplicity I can't get to work...
    My login code:
    
    <?php
       $bruger = $_POST['username'];
        setcookie('member',$bruger);
    ?>
    
    Code (markup):
    My log out code:
    
    setcookie('member', time()-3600);
    
    Code (markup):
    Problem is that I can't destroy the cookie, thereby logging the user out... Could anyone please help me here?

    Thanks.
     
    lruneh, Dec 2, 2008 IP
  2. iDemonix

    iDemonix Peon

    Messages:
    37
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The syntax for setcookie is;

    setcookie ( string $name [, string $value [, int $expire [, string $path [, string $domain [, bool $secure [, bool $httponly ]]]]]] )

    so it should be setcookie('member', '', time()-3600); to log a user out.
     
    iDemonix, Dec 2, 2008 IP
  3. lruneh

    lruneh Peon

    Messages:
    72
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi iDemonix

    THanks for your reply.
    Unfortunately it doesn't seem to work. The cookie is still set, and the user logged in
     
    lruneh, Dec 2, 2008 IP
  4. qualityfirst

    qualityfirst Peon

    Messages:
    147
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    0
    #4
    Try this:

    setcookie('member', "", time()-3600);
     
    qualityfirst, Dec 2, 2008 IP
  5. Mr.Shan0

    Mr.Shan0 Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try This:
    i think problem is in ur login script so try this login script :)

    Login Script:
    setcookie('member', $bruger, time() + 3600);
    Code (markup):
    Logout Script:
    setcookie("member", "", time() - 3600 , '/');
    Code (markup):
     
    Mr.Shan0, Dec 3, 2008 IP