SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been having a weird problem with PHP cookies recently. Several projects I am working on (including ssLinks in my signature) use PHP powered cookie based user authentication. Basically you log in and the script sets a cookie containing either your usename and password or a sessionn variable to show that you are logged in. That is then checked at the beginning of every protected page.

    Here's the problem - it seems some installations of internet explorer refuse to work when logging in in this method. At first I didn't believe this when I was told by a friend that they couldn't log in but at the weekend I experienced this effect on a computer at an internet café.

    Here's the code that isn't working (taken from ssLinks):
    PHP Code:
    function login($username$password)
    {
        
    setcookie("Links_Cookie_User"$usernametime() + 3600);
        
    setcookie("Links_Cookie_Pass"$passwordtime() + 3600);
        
    header("Location: links.php");
        exit;

    This is called with the values from the login form. links.php checks for a cookie when it is loaded and displays admin options if the user is logged in - however the bug I am describing results in no admin options displayed. I checked in the c:\Windows\cookies directory on the affected system and no cookie had been sent - but the vast majority of browsers (including every version of MSIE - one of our test guys had a look) recieve a cookie and log in fine.

    And before you ask - this bug is not down to cookies being turned off in the browser as the same browsers accessed and logged into a vBulletin 1.1.5 powered forum fine.

    Any ideas?

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't really know anything about cookies. But the first thing that hits my mind while its in debugging mode is:

    setcookie("Links_Cookie_User",*$username,*time()*+*3600);

    Should this be:

    setcookie("Links_Cookie_User",*"$username",*time()*+*3600);

    and similarly

    setcookie("Links_Cookie_Pass",*"$password",*time()*+*3600);

    I'm guessing that if the IE is expecting the second arguement, as a string, needs to be wrapped in quotation marks.

    Just a guess.

  3. #3
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The string shouldn't need quotes since it is already contained in a variable - sticking quotes around the variable just causes PHP to parse the string inside the quotes - which results in exactly the same thing. Seeing as Internet Explorer gets the cookie on almost all PCs (I've only had 2 occasions where it hasn't worked, but since one of them was on a PC belonging to a guy who NEEDS to use the system I'm developing I have to get a solution) I'm certain it's nothing to do with the lack of quotes.

  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes thinking about it, I guess you are right. I was thinking about what the final code should look like rather than semantics of the call to function setcookie()

  5. #5
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you using IIS as your web server? Because there's a bug with IIS4 (NT) and 5 (Win2K) that causes this problem:

    http://support.microsoft.com/support.../q176/1/13.asp

    Read the user comments here:
    http://www.php.net/manual/en/function.setcookie.php

    You might find the solution.

  6. #6
    SitePoint Columnist Skunk's Avatar
    Join Date
    Jan 2001
    Location
    Lawrence, Kansas
    Posts
    2,066
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm using Apache running on windows 2000.

    MattR - thanks for pointing me at those comments in the PHP manual (I should have looked earlier but I completely forgot about them) - I'm pretty sure I've found the solution in there

    cheers,

    Skunk

  7. #7
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem.

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can we ask what the solution was?

    It may help u in the future

    Peter


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
  •