Cookie not being saved in IE 8

This function is not saving the data in the Internet Temporary Files folder. Any reason why (Windows 7, IE 8)?
function setCookie(name, value, expires, path, domain, secure)
{
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
DistillingExpertsAsked:
Who is Participating?
 
Ray PaseurCommented:
I am fairly sure that is not PHP code, because PHP already has a function named setcookie() so the definition of a new function named setcookie() will cause a fatal error.  I think what you have there is a piece of JavaScript.   You can use the "Request Attention" link to ask a moderator to add this question to the JavaScript Zone.

But before you do that, consider whether setting cookies in Javascript is a good idea.  JavaScript cookies may represent a security threat.  Make a Google search for "javascript cookie security" and learn about cross-site scripting.  If you decide you want to set your cookies in the PHP script we can show you how to do that, and how to hide the cookies from JavaScript.
0
 
Beverley PortlockCommented:
This looks more like Javascript than PHP, so I think you might need to repost it in the javascript forum..... still from the code above my first guess would be that expires.toGMTString() is outputting either the current time or a historic time. In either of these cases the cookie expires as soon as you write it. Check expires.toGMTString() and make sure its expiry is in the future - even if only an hour.

Next, have you checked if these expires in other browsers because you only mention IE8. If it is OK in other browsers then check the following items which are known to cause cookie problems for IE

1. What is the server's clock showing for time. If the server's clock is different from yours IE will expire the cookie

2. Does the website contain an underscore in the domain name? If so then IE tends to drops sessions and cookies

Try that lot out and post back with the results.
0
 
Mohamed AbowardaSoftware EngineerCommented:
Make sure that cookies is not disabled on IE.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.