SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I am creating a script that uses cookies to store login/password information. It works if you stay on the internet, but when you put in your correct username/password and then log off of the internet, and then try to access the page again, it will show up the login and password form fields.

    Is there anyway to access a cookie on a visitors' computer, after they've logged off of the Internet, so that the only time they will have to input their username and password is when they delete the cookies on their computer?

    Thanks!

    Chris Roane

  2. #2
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'd have to set the number of seconds to a very high number I believe - can you show us your setcookie code?

  3. #3
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the code that goes on top of all the administration pages:

    ----------------------------------------
    require("important/functions.php3");
    If (!($cookie_user)) {
    If (!authenticateUser($cookie_user, $cookie_passwd)) {
    echo("<P><B>You must login.</B></P>");
    include("login.html");
    exit;
    }
    }
    ----------------------------------------


    Here is the authenticateUser() function, in the functions.php3 file.

    ----------------------------------------
    function authenticateUser($user, $password)
    {
    If($file = fopen("important/password.txt", "r")) {
    $files = fread($file, 500);
    $files = split("/", "$files");
    $real_username = $files[0];
    $real_password = $files[1];
    If (($user == $real_username) && ($password == $real_password)) {
    setcookie ("cookie_user","$user");
    setcookie ("cookie_passwd","$password");
    Header("Location: index.php3");
    } // end if statement
    } // end if statement

    } // end function
    ----------------------------------------

    Thanks!

    Chris Roane

  4. #4
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need another attribute added to your cookie:

    Code:
    setcookie ("cookier_user", $user,time()+604800);
    The number at the end is the number of seconds (I think) before it expires. 3600 equals one minute - from there, it's a simple multiplication problem. The number there now should be one week's worth of seconds, roughly.

    Hope that helps.

  5. #5
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! It worked.

    Chris Roane

  6. #6
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to have helped! The cookie stuff really intimidated me at first, but it's pretty simple - and really dang cool!

  7. #7
    SitePoint Addict Chris Roane's Avatar
    Join Date
    Jul 1999
    Location
    Helena, MT
    Posts
    287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, your right. It seems like it might be pretty complicated but to tell you the truth, it is one of the simplest things to do with PHP.

    Chris Roane


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
  •