Jump to content

Handling Cookies in IE


smnw10

Recommended Posts

I am completely baffled here and can't find a solution on the web, in books, or even quickly in this forum. I just need a simple script to set the username and password as a cookie to keep the user logged in over a period of time.
The script work without any problems in firefox, but won't work at all in IE. Even the simplest code to set a cookie, then display it on the next page will not work in IE. It appears that the cookie doesn't get set in IE.

if I have:
[code]
<?PHP
setcookie("user", $username, time()+3600);
?>
[/code]

then on another page have:
[code]
<?PHP
echo "cookie is ".$_COOKIE['user'];
?>
[/code]
my output is only:
cookie is

and doesn't display the cookie content.

There was some code to display all cookies that are set, and the output in IE after I try to set the cookie and then display all cookies is just:
Array()

but in FireFox, using the exact same pages, it works without a problem and displays the cookies and their content for me.

what the heck am I doing wrong???

thanks
John
Link to comment
Share on other sites

You can turn off cookies in any browser. Perhaps your version of IE has the ability to receive cookies turned off. More browsers will accept a cookie if you DO NOT give it an expiration date. That type of cookie is deleted as soon as the browser window closes.

Two points:
1) Cookies are an unreliable solution for sessions in general. You need a backup plan, usually placing a session identifier in the URL for every link on your site.

2) Sending a username and a password in a cookie is not very secure. The preferred method is to send a random string of characters that can be matched up on your end with the correct username.
Link to comment
Share on other sites

thanks for the quick reply
I understand the security risk with using the username and pass in a cookie, for what this site entails there is no risk though.
the person I'm dealing with wants the user to be able to choose to stay logged in for 30 days if they want. So, I figured the best way is just use a cookie and set it to expire in 30 days when they choose that option. The site was running fine with sessions but they didn't like that when they tried to get back on the site the next day or a few hours later, they had to log back in.

I have my IE set to accept all cookies. And I tried viewing the site with anotehr computer and had the exact same results with IE.

I just tried setting the cookie without declaring an expiration time and it worked in IE.
What's the default time for a cookie to last when you don't declare an expiration time?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.