SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot infoxicated's Avatar
    Join Date
    Jun 2001
    Location
    UK
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE5 cookie grabbing problem

    I have this script set up on an intranet I'm working on, where a user can log in to the site and click a little "remember me" check box.

    This sets a cookie with their username and password. The next time they visit, the Javascript grabs the cookie details and then auto-forwards them to the login page where they are logged in and then taken to the start-up page of their choice.

    This works perfectly in IE 6, but I've discovered that on IE 5 it doesn't grab the cookie details. From the code below, does anyone have any ideas why?

    Re-direction bit:
    Code:
    <script>
    if (getCookie('username') && getCookie('password')){
       document.location="admin.php?action=authorise&username=" + getCookie('username') + "&password=" + getCookie('password') + "&autologin=true";	};
    </script>
    Cookie Grabber:
    Code:
    function getCookie (name) {
    var cname = name + "=";
    var clen = document.cookie.length;
    var cbegin = 0;
    
    while (cbegin < clen) { 
    var vbegin = cbegin + cname.length;
    
    if (document.cookie.substring(cbegin, vbegin) == cname) { 
    	var vend = document.cookie.indexOf (";", vbegin);
    if (vend == -1) vend = clen;
    	return unescape(document.cookie.substring(vbegin, vend));
    }
    
    cbegin = document.cookie.indexOf(" ", cbegin) + 1;
    
    if (cbegin== 0) break;
    }
    return null;
    }
    I didn't write the second bit - I just grabbed it from hotscripts or somewhere

  2. #2
    SitePoint Zealot infoxicated's Avatar
    Join Date
    Jun 2001
    Location
    UK
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I found out what was wrong, so I figure I'll reply to myself in order to help other dudes if they have the same problem

    What seems to be the case, is that IE 6 treats NULL and FALSE as the same kind of thing, but IE 5 doesn't, so NULL is not FALSE.

    So when I was looking to see if the cookie variables were false, they weren't, they were NULL, which was then screwing up things in IE 5 as it tried to log folk in automatically anyway.

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was going to say that earlier, but i had my maths exam at the time an i forgott to post it lol.

    Have you got it working if not i will post a variation of the code you have later

  4. #4
    SitePoint Zealot infoxicated's Avatar
    Join Date
    Jun 2001
    Location
    UK
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it's working now... or rather, the three folk who've been assigned to test the site haven't complained yet, so I guess it's ok!

    Hope the exam went well.

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are they using different browsers etc?

    As this is what makes all the difference.

    ps nah i think i failed


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
  •