Forum Moderators: phranque

Message Too Old, No Replies

IE6 and Cookies (Again it seems.....)

Why IE6 will not *display* my cookie

         

Roberta_H

6:12 pm on May 17, 2003 (gmt 0)

10+ Year Member



Hello all,

My first post here.

This is my situation. I'm using IE6 and have put together a site using MySQL/PHP and DW MX. I have a login page which checks the form details against a database of users and passes valid users to the next page.

On the 'loginSuccessful' page I have a piece of code which simple echo(es) the user cookie to the scree in this fashion.

Hello (Cookie) welcome to my site.

IE6 does not display this, I just see

Hello welcome to my site.

Which is fine of course, but I need to know why this is the case. It's an IE6 issue as it works in IE5, Opera 7 and Netscape 7. I have set my privacy settings to overide automatic cookie settings and have set 1st and 3rd party cookies to accept.

This cookie is a simple 1st party session cookie so whats the problem? Can it be the P3P thing I've read about? Will I need a compact privacy xml document? After reading all posts on this forum about IE6/Cookies I don't think so.

Hope someone can help clarify this for me.

Kind regards

Roberta

grahamstewart

5:58 pm on May 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can see how IE6 is handling your cookies by going to View->Privacy Report..

This should tell you if your cookie gets blocked. You may also notice a little 'eye' icon in the status bar at the bottom.

Roberta_H

6:54 pm on May 19, 2003 (gmt 0)

10+ Year Member



IE6 displays 'accept all cookies' and the eye symbol does not appear.

This really is annoying.

Rob

grahamstewart

8:46 pm on May 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are making it to the welcome screen does that mean the cookie is properly set?

If so then is the problem just with the way you output the value of the cookie?

Roberta_H

6:28 am on May 20, 2003 (gmt 0)

10+ Year Member



Yes, that's a good point. Ok this is the way the cookie value is output to the screen ;

<p>Hello

<?php

echo $HTTP_COOKIE_VARS['cookieName'];

?>

welcome to my site</p>

It looks right but am I missing a fundemental problem here?

Roberta

grahamstewart

12:20 pm on May 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The only thing I see wrong with that is that HTTP_COOKIE_VARS is deprecated (the correct way to access cookie data is through the $_COOKIE autoglobal variable).
See [php.net...]

But HTTP_COOKIE_VARS is still supported so I don't think thats causing the problem.

I guess your problem is probably with IE blocking the cookie.

Lets see if it is getting set...

[pre]
<?php

if ( isset($_COOKIE['cookieName']) )
print "Cookie is set: '".$_COOKIE['cookieName']."'";
else
print "Cookie not set.";
?>
[/pre]

Also I note you said this was a 'session cookie', in which case shouldn't you be using session_start() and $_SESSION?
[php.net...]

Roberta_H

2:10 pm on May 20, 2003 (gmt 0)

10+ Year Member



Hello

Your last post sent me off on a deturmined path to find out what was going on. This is what I found.

FIRST PAGE

setCookie("testCookie", $temp, time() + '0', "/");

($temp is the value passed from a form)

TEST PAGE

when passed onto the test page;

if (isset ($HTTP_COOKIE_VARS['testCookie']) )

print "Cookie is set to : " . $HTTP_COOKIE_VARS['testCookie'];

else

print "Cookie not set"

shows Cookie not set.

Now for the intersting bit.

If I do this

setCookie("testCookie", $temp);

I recieve this

Cookie is sent to : (whatever $temp is set to)

So it works without the other parameters on the setCookie function. I have tried lots of different permutations of this and when I changed the time value from '0' to simply 3600 it also worked. Even setting to 1 will work.

Now for a session cookie I thought I could set it to 0 so that when the user closes the browser the cookies is terminated. So its ideal for user validation for example.

Well I sort of got it to work but I am still confused over the session aspect of it and the value 0.

Oh well

Regards

Roberta

grahamstewart

6:15 pm on May 20, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For sessions you shouldn't have to mess with cookies directly at all.

You just go..


session_start();
$_SESSION['userLoggedIn'] = TRUE;
$_SESSION['username'] = 'bob';

..on the first page and then..
[pre]
session_start();

if ( isset(_SESSION['userLoggedIn']) and $_SESSION['userLoggedIn'] )
print '<p>You are currently logged in '.$_SESSION['username'].'</p>';
else
print '<p>Not logged in.</p>
[/pre]

..on other pages.

You just need to make sure that session_start() is called before any text is sent (i.e. before your <html>)

theFog

1:14 pm on Jun 6, 2003 (gmt 0)



I had the same problem. It's the time value of the cookie that's at issue here.

Set the expiration time to a higher value.

I had two cookies that I was setting - the first was for session-ish information (which had an expiration time of at least 3600). It worked fine in IE6. The second cookie was engineered to have a very short life since it's contents were consumed quickly by the user, so I set the expiration time to 30 seconds from now. That cookie worked fine in IE 5.5, Moz, KHTML, etc, but didn't work at all in IE6.

I was setting the cookie using PHP, and I was calculating the base time using the php time() function. time() was returning to me the server time, which i noticed was behind the client machine by a few minutes. IE6 never took the cookie, which had an expiration date it percived to be in the 'past'. When I increased the expiration date to make up for the difference in system times IE accepted the cookie.