Forum Moderators: phranque
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
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...]
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
You just go..
session_start();
$_SESSION['userLoggedIn'] = TRUE;
$_SESSION['username'] = 'bob';
[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] You just need to make sure that session_start() is called before any text is sent (i.e. before your <html>)
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.