|
|
|
06-15-1999, 02:29 PM
|
Postid: 42714
|
|
Fond of TAZ
Join Date: Feb 1999
Posts: 919
|
Cookies in PHP with IE and Netscape
Wow, I finally get my cookies working in PHP, and realize that they don't work at all in Internet Exploder, imagine that. I'm assuming its a Microsoft problem, just because I like blaming them.
I've heard over at php.net that:
--Microsoft Internet Explorer 4 with Service Pack 1 applied does not correctly deal with cookies that have their path parameter set.
--Netscape Communicator 4.05 and Microsoft Internet Explorer 3.x appear to handle cookies incorrectly when the path and time are not set.
I also read that if you have a Header() statement after a SetCookie(), that the SetCookie() won't even be performed, because IE will issue the Header() first. The fix for this problem (do the Header() in an INCLUDEd module), didn't work for me.
I'm currently not setting the path (only the time, one hour) in my cookie, and I'm using Netscape 4.6. It seems to work fine with that.
Has anybody interpreted if there's a cookie setting that will work with ALL browsers, or will I have to have code for each flavor? If I have to do it this way, I'll post what I come up with here.
I don't have MySQL yet, so I don't have access to trying out PHPLib.
|
|
|
06-15-1999, 04:01 PM
|
Postid: 42715
|
|
Visitor
Join Date: Jan 1999
Location: Kissimmee, FL
Posts: 3,672
|
I always just use this:
setcookie ("cookie_name", "cookie_data", time() + 86400);
Which would set it for one day. I don't usually use a path - I just try to make sure the cookie name is unique enough to not cause problems with other scripts. You never know when you might decide you want to use that data in another script elsewhere on the same domain...
I know the above works in IE4, IE5, and NN 4.08. If you want though, you can set the cookie manually using the header() function:
header("Set-Cookie: cookie_name=cookie_data; expires=Wed, 31-Dec-1999 00:00:00 GMT; path=/ domain=domain.com"  ;
Or something like that - I haven't tested it though... I just think setcookie() is easier and it does work on the newer browsers...
HTH
<!-- NO_AUTO_LINK -->
------------------
Justin Nelson
FutureQuest Support
|
|
|
06-15-1999, 05:09 PM
|
Postid: 42716
|
|
Fond of TAZ
Join Date: Feb 1999
Posts: 919
|
That's what I'm using too. I'll send you the location that I'm trying to test out. It works fine in Netscape 4 and greater, but not in Explorer version 4.x (I'd have to check the release and/or Service Pack number).
And is it true that if I wanted to just set a session cookie, I'd just set the time to 0?
|
|
|
06-15-1999, 05:25 PM
|
Postid: 42717
|
|
Visitor
Join Date: Jan 1999
Location: Kissimmee, FL
Posts: 3,672
|
I checked out the URL you sent me, but I'm using IE5 - works here...
Session cookies I have had problems with - I think you have to set the time to something in the past, but I could never get it to work.
I know to delete a cookie you just set it with no value or time - just setcookie("cookie_name"  ; will delete it. What I do for session cookies is set it to expire in one day and have a LogOut button that will then delete the cookie - it seems to be an easier way to do it (I think that's how Hotmail does it). Not sure about the proper way to set a session cookie.
I'm using the logout idea for my banner script, where advertisers will be able to login and see their banner stats and upload new banners, etc - session cookies just seem really buggy from PHP...
What exactly does your code do at the URL you sent me? Here's how I handle cookies to avoid confusion: I set the cookie name different from the variable name that I use - otherwise you can't re-login as someone else until the cookie is expired:
Code Sample:
<?
if ($c_username)
$username = $c_username;
if ($c_password)
$password = $c_password;
?>
|
|
And for the actual login page:
Code Sample:
<input type=text name=username>
<input type=text name=password>
|
|
And the page that sets the cookie:
Code Sample:
<?
if ($username)
setcookie("c_username", $username, time() + 86400);
if ($password)
setcookie("c_password", $password, time() + 86400);
?>
|
|
The reason I do this is because cookie variables take precedence over form data - so if there is a cookie called $username, you can't overwrite that with a form field called $username - of course you can use $HTTP_GET_VARS, $HTTP_POST_VARS and $HTTP_COOKIE_VARS and override the automatic variable conversion, but it's just easier to use a different name for the cookie than for your variables (I do all of the above in the header so it really doesn't pose a problem - it's all automatic  )
Hope this helps
------------------
Justin Nelson
FutureQuest Support
|
|
|
06-15-1999, 05:33 PM
|
Postid: 42718
|
|
Fond of TAZ
Join Date: Feb 1999
Posts: 919
|
Justin, I'm using mine the same way (basically), not a session cookie, just a "normal" cookie that lasts an hour. They shouldn't be mucking around in there longer than that, and if/when they do, they just get sent to the main Login page again.
When somebody goes to the "home" page of the script, the first thing it does is delete the cookie, then sets it when they enter their username and password.
I'll see if I can change some things, and see if I can get it to work with IE 4.0, or I'll just tell the IE users to upgrade, they'll love that!
Thanks!
Sneaky
|
|
|
06-15-1999, 07:16 PM
|
Postid: 42719
|
|
Fond of TAZ
Join Date: Feb 1999
Posts: 919
|
I have version 4 of IE with Service Pack 1, and it works on my machine.
Can some other people with IE version 4 try out this site (use "demo" for the userid and "123" for the password, no quotes), and let me know if they get an error message?
http://www.little-treasures.net/ihost/upload.php3
You should have a message at the top of the page that says "Hello, demo"...
Thanks for anybody's and everybody's time.
|
|
|
06-16-1999, 08:46 AM
|
Postid: 42720
|
|
Visitor
Join Date: Dec 1998
Location: Near Daytona Beach USA
Posts: 406
|
Geez, Dave.. I can't keep up with you, you're everywhere! 
I tried it out using a freshly installed IE4.0 (4.72.3110 to be exact) and did not get an error message.. I see the "Welcome demo, You currently have 2 images"..etc. Hope this helps,
Paul
|
|
|
06-16-1999, 09:45 AM
|
Postid: 42721
|
|
Fond of TAZ
Join Date: Feb 1999
Posts: 919
|
Thanks Paul, I know somebody that had the same version installed, and got an error (it wouldn't set the cookie, and caused a hullabaloo). They installed Service Pack 2, and still got the error.
I'm going to try to use the header(SetCookie) command to see if that will fix it.
Thanks
Sneaky
<edit>Edited for goofiness</edit>
[This message has been edited by SneakyDave (edited 06-16-99)]
|
|
|
06-16-1999, 10:03 AM
|
Postid: 42722
|
|
Visitor
Join Date: Dec 1998
Location: Decatur, GA 30032
Posts: 447
|
If you specify the domain in the cookie headers, you'll need at least 2 dots/periods.. so if you set for the domain bobsbigbobsleds.com, you'll want to specify the domain as
Code Sample:
HTH,
Jake
------------------
icongarden.com/?fq
icongarden: making good ideas grow.
|
|
|
06-16-1999, 10:18 AM
|
Postid: 42723
|
|
Fond of TAZ
Join Date: Feb 1999
Posts: 919
|
Jacob, I'm currently not using the domain (just the name, data, and the time), but I'm willing to try just about anything.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 10:05 PM.
|
| |
|
|
|