p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: setcookie function doesn't work on IE on Macs?


Message #1 by spam@k... on Mon, 9 Sep 2002 21:41:22
I've written a simple content management system. To control a web site, a 
user goes to a special page and logs in, and from there can add, edit, 
delete pages. The login uses the set_cookie() function. (I had a little 
trouble with sessions, so I switched to setcookie.) This thing works fine 
on PCs. However, I have a friend whose using it from a Mac. She keeps 
sending me bug reports about what doesn't work on the Mac. She just sent 
me this: 

> Also, using internet exploreer 5.1 (whihc I
> believe is the latest version available for macs) it
> doesnt let you edit anything as a  staff member. You login, you go to
> the page after the password part, but you cant go any
> further, it always returns you to the password part.

Clearly, the cookie isn't being set. Can anyone think of a reason why? Are 
there any known issues with IE on the Mac and cookies? The login function 
is below. 


function checkPassword() {

	global $self, $password, $mcPassword, $pathToIndex;

	setcookie('password', $password, time() + 3600);

	// $mcPassword is the password that is set in the config file or 
in the database.

	if ($password != $mcPassword){

		setcookie('password', $password, time() - 3600);

		echo "

		<table cellpadding='6px' border='1'>

		<tr><td>

		This part of the website is restricted to employees. 

		If you are not an employee, 

		<a href='$pathToIndex'>

		please click here to return to the main part of this site.

		</a>

		</td><td>

		<form method='post' action='$self'>

		Please type your password here:<br>

		<input type='password' name='password'><br>

		<input type='submit'>

		</form>

		</td></tr></table>

		";

               die();

	} 

}
Message #2 by Jason DeWitt <roxet@c...> on Mon, 09 Sep 2002 15:49:21 -0500
I just looked this over very quickly, but here's what I noticed.

In your setcookie function you might try to pass it *every* parameter it 
wants, even if it is an empty string. Also, you set the expires to 
"time() - 3600", isn't that setting the cookie to expire in the past? 
Maybe that is why it's not working.

I had alot of problems with cookies not too long ago, sadly I don't 
remember what fixed it. My problem was it was working in IE but not 
Mozilla, then I got it to work in Mozilla but it stopped working in IE.

You might also try using the header() function to set your cookie.

spam@k... wrote:
> I've written a simple content management system. To control a web site, a 
> user goes to a special page and logs in, and from there can add, edit, 
> delete pages. The login uses the set_cookie() function. (I had a little 
> trouble with sessions, so I switched to setcookie.) This thing works fine 
> on PCs. However, I have a friend whose using it from a Mac. She keeps 
> sending me bug reports about what doesn't work on the Mac. She just sent 
> me this: 
> 
> 
>>Also, using internet exploreer 5.1 (whihc I
>>believe is the latest version available for macs) it
>>doesnt let you edit anything as a  staff member. You login, you go to
>>the page after the password part, but you cant go any
>>further, it always returns you to the password part.
> 
> 
> Clearly, the cookie isn't being set. Can anyone think of a reason why? Are 
> there any known issues with IE on the Mac and cookies? The login function 
> is below. 
> 
> 
> function checkPassword() {
> 
> 	global $self, $password, $mcPassword, $pathToIndex;
> 
> 	setcookie('password', $password, time() + 3600);
> 
> 	// $mcPassword is the password that is set in the config file or 
> in the database.
> 
> 	if ($password != $mcPassword){
> 
> 		setcookie('password', $password, time() - 3600);
> 
> 		echo "
> 
> 		<table cellpadding='6px' border='1'>
> 
> 		<tr><td>
> 
> 		This part of the website is restricted to employees. 
> 
> 		If you are not an employee, 
> 
> 		<a href='$pathToIndex'>
> 
> 		please click here to return to the main part of this site.
> 
> 		</a>
> 
> 		</td><td>
> 
> 		<form method='post' action='$self'>
> 
> 		Please type your password here:<br>
> 
> 		<input type='password' name='password'><br>
> 
> 		<input type='submit'>
> 
> 		</form>
> 
> 		</td></tr></table>
> 
> 		";
> 
>                die();
> 
> 	} 
> 
> }
> 


Message #3 by spam@k... on Mon, 9 Sep 2002 15:52:05 -0500
> In your setcookie function you might try to pass it *every* parameter it 
> wants, even if it is an empty string. 

Worth a shot, I guess. 




>Also, you set the expires to 
> "time() - 3600", isn't that setting the cookie to expire in the past? 
> Maybe that is why it's not working.

Of course, that is to kill the cookie. This is wrapped in an if clause, when the password is bad. If the password is bad, then kill
the cookie. 
Message #4 by Jason DeWitt <roxet@c...> on Mon, 09 Sep 2002 16:03:59 -0500
Doh! Like I said, I read over it real quick. I'm pretending to be busy 
today. =)

The main thing I wanted to point out was to try passing all the 
parameters, but I noticed the -3600 thing. Thought it might be one of 
those things that you've stared at for so long it looks right. =)

>>Also, you set the expires to 
>>"time() - 3600", isn't that setting the cookie to expire in the past? 
>>Maybe that is why it's not working.
> 
> 
> Of course, that is to kill the cookie. This is wrapped in an if clause, when the password is bad. If the password is bad, then
kill the cookie. 
> 

Message #5 by Krister <krister@m...> on Tue, 10 Sep 2002 01:41:13 +0200
On 09/09/02 21:41, "spam@k..." <spam@k...> wrote:

> I've written a simple content management system. To control a web site, a
> user goes to a special page and logs in, and from there can add, edit,
> delete pages. The login uses the set_cookie() function. (I had a little
> trouble with sessions, so I switched to setcookie.) This thing works fine
> on PCs. However, I have a friend whose using it from a Mac. She keeps
> sending me bug reports about what doesn't work on the Mac. She just sent
> me this: 
> 
>> Also, using internet exploreer 5.1 (whihc I
>> believe is the latest version available for macs) it
>> doesnt let you edit anything as a  staff member. You login, you go to
>> the page after the password part, but you cant go any
>> further, it always returns you to the password part.
> 
> Clearly, the cookie isn't being set. Can anyone think of a reason why? Are
> there any known issues with IE on the Mac and cookies? The login function
> is below. 
> 
> 
> function checkPassword() {
> 
> global $self, $password, $mcPassword, $pathToIndex;
> 
> setcookie('password', $password, time() + 3600);
> 
> // $mcPassword is the password that is set in the config file or
> in the database.
> 
> if ($password != $mcPassword){
> 
> setcookie('password', $password, time() - 3600);
> 
> echo "
> 
> <table cellpadding='6px' border='1'>
> 
> <tr><td>
> 
> This part of the website is restricted to employees.
> 
> If you are not an employee,
> 
> <a href='$pathToIndex'>
> 
> please click here to return to the main part of this site.
> 
> </a>
> 
> </td><td>
> 
> <form method='post' action='$self'>
> 
> Please type your password here:<br>
> 
> <input type='password' name='password'><br>
> 
> <input type='submit'>
> 
> </form>
> 
> </td></tr></table>
> 
> ";
> 
>              die();
> 
> } 
> 
> }

Hi

I'm using Explorer 5.2.1/ Macintosh(...and Netscape7.0...) and I don't have
any problems with cookies or sessions. Cookies are turned on as Explorer
default.

I had also a problem with sessions, but I solved it by giving both
read/write permissions to its saving folder addressed in php.ini

http://www.ScriptBreaker.com has a nice javascript to check if cookies are
enabled in case you can check your friends Mac.

Krister









 

Message #6 by spam@k... on Fri, 13 Sep 2002 13:14:43 -0500
> I'm using Explorer 5.2.1/ Macintosh(...and Netscape7.0...) and 
> I don't have
> any problems with cookies or sessions. Cookies are turned on 
> as Explorer
> default.
> I had also a problem with sessions, but I solved it by giving 
>both
> read/write permissions to its saving folder addressed in 
>php.ini

Interesting that you didn't have any problems. She's got 5.5 but it seems like an unlikely bug. A browser that can't read cookies
isn't worth much. 

I'm working in a hosted environment so I can't control the php.ini file. But that is a good tip for when I set up my first server,
which I'll be doing this month. 

On www.php.net in the user comments I saw a lot of comments like this: "After experiencing the infamous IE problem at work with our
installation of Double Choco Latte (no code posted yet, but the curious can visit http://dcl.netpedia.net), I felt compelled to
share my findings here." But no one really spelled out what the problem was. 

I'm going to try to set all 6 variables and see if that helps. (But doesn't the PHP function set all 6, even if I don't?). 



  Return to Index