What's wrong with this login and logout script?

Discussion in 'PHP' started by hhheng, Jul 19, 2008.

  1. #1
    Login script:
    Logout Script:
    Problem with the above script:
    • If I put the login script in the header for several files, login any file and then launch other files will not require the login again, it will go straight to the logged in page.
    • By just clicking logout, it will log out, but if you type in the url again, it will still go straight to the logged in page without requiring logging username and password.
    • The page will be only expired until reach the 7200 time limit.
    • While in the logged in pages, if we close the browser or turned to outside pages, and then type in the url for the pages again, they will not require logging username and password.
    What i want is by clicking logout and then will require logging username and password to go back to the page, and while in the logged in page, if we close the browser, or turned to other page, and then come back again, will require logging username and password again.
     
    hhheng, Jul 19, 2008 IP
  2. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It looks to me like you aren't unsetting the user cookie :

    setcookie("user", $_POST[user], time()-7200, "/", str_replace(".", "", $_SERVER[HTTP_SERVER_NAME]));

    Try removing the "@"'s and see if the script error's.
     
    Cri2T, Jul 19, 2008 IP
  3. hhheng

    hhheng Banned

    Messages:
    2,633
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you change it to 7200, the page will be never expired.

    I tried to remove the "@", but it's not working. Can anybody help me?
     
    hhheng, Jul 20, 2008 IP
  4. coder 525

    coder 525 Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    coder 525, Jul 21, 2008 IP
  5. Cri2T

    Cri2T Peon

    Messages:
    104
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What do you mean by not working?

    @ sign suppresses error messages, so if you remove it and get an error message, then try to find the source of the error message (if you can't, post it on here and I'll try to figure it out) and correct it.

    Your script looks like it should work.


    Also, when unsetting a cookie you must set it with the exact parameters you set it with when you created it (except you change the + to a - on the expire time).
     
    Cri2T, Jul 21, 2008 IP
  6. hhheng

    hhheng Banned

    Messages:
    2,633
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Cri2T, shall I use time()-7200 or time()+7200?
     
    hhheng, Jul 25, 2008 IP
  7. hhheng

    hhheng Banned

    Messages:
    2,633
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Cri2T, I did as you said, but it's still the same problem. Can anybody help me for this login and logout script?
     
    hhheng, Aug 1, 2008 IP