Cookie not being saved in IE 8

Posted on 2011-04-21
Last Modified: 2012-05-11
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;
Question by:DistillingExperts
    LVL 34

    Expert Comment

    by:Beverley Portlock
    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.
    LVL 12

    Expert Comment

    by:Mohamed Abowarda
    Make sure that cookies is not disabled on IE.
    LVL 107

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    One of the features I've come to appreciate about Windows 7 and Windows Server 2008 R2 is the ability to pin applications to the task bar. As useful a feature as I've found this, it does have some quirks.  For example, have you ever tried pinning an…
    First some basics on Windows 7 Backup.  It has 2 components one is a file based backup which is stored in .zip files each zip is split at around 200 Megabytes and there is the Image Backup which is as the name implies a total image of the partition …
    This Micro Tutorial will go in depth within Systems and Security in Windows 7 and will go into detail regarding Action Center, Windows Firewall, System, etc. This will be demonstrated using Windows 7 operating system.
    This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now