Can't set session cookie???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brett

    Can't set session cookie???

    I'd like to set a session cookie that expires once the browser is
    closed. I've tried:

    document.cookie = "wm_javascript= " + escape("SomeNam e|" +
    window.document .referrer);

    with no expires. This doesn't set a cookie. It seems I must put in
    an expiration for the cookie to set. The code below does work:

    var the_name = window.document .referrer;
    var the_cookie = "wm_javascript= " + escape("SomeNam e|" + the_name);
    var the_date = new Date("December 31, 2050");
    var the_cookie_date = the_date.toGMTS tring();
    the_cookie = the_cookie + ";expires=" + the_date.toGMTS tring();
    document.cookie = the_cookie;

    Why doesn't the session cookie set? I'm using IE6.

    Also, if a user has multiple IE windows open, will the session cookie
    expires only after all IE windows have closed?

    Thanks,
    Brett
  • Thomas 'PointedEars' Lahn

    #2
    Re: Can't set session cookie???

    Brett wrote:[color=blue]
    > document.cookie = "wm_javascript= " + escape("SomeNam e|" +
    > window.document .referrer);
    > with no expires. This doesn't set a cookie. It seems I must put in
    > an expiration for the cookie to set. The code below does work:
    >
    > var the_name = window.document .referrer;[/color]

    document.referr er is unreliable and using it is error-prone.
    [color=blue]
    > var the_cookie = "wm_javascript= " + escape("SomeNam e|" + the_name);
    > var the_date = new Date("December 31, 2050");[/color]

    Using date strings is error-prone because interpretation is
    implementation-dependent. Use several arguments instead:

    var the_date = new Date(2050, 11, 31);
    [color=blue]
    > var the_cookie_date = the_date.toGMTS tring();
    > the_cookie = the_cookie + ";expires=" + the_date.toGMTS tring();
    > document.cookie = the_cookie;
    >
    > Why doesn't the session cookie set? I'm using IE6.[/color]

    Implementations usually follow the Netscape cookie specification:

    <http://devedge.netscap e.com/library/manuals/2000/javascript/1.3/reference/cookies.html#10 02170>

    Some UAs set cookies only if set by a resource retrieved via HTTP, thus
    they do not set it with documents accessed with "file:" URIs, for example.
    Some UAs consider cookies without "domain=" invalid and will not set those.
    [color=blue]
    > Also, if a user has multiple IE windows open, will the session cookie
    > expires only after all IE windows have closed?[/color]

    Possibly.


    PointedEars

    Comment

    • Robert

      #3
      Re: Can't set session cookie???

      In article <c003b25a.04072 71637.606d964c@ posting.google. com>,
      account@cygen.c om (Brett) wrote:
      [color=blue]
      > I'd like to set a session cookie that expires once the browser is
      > closed. I've tried:
      >[/color]
      [color=blue]
      >
      > Why doesn't the session cookie set? I'm using IE6.[/color]

      I found it best to always set the date and time in IE. Figure out how
      long you need to use the cookie and add a reasonable about of extra time
      like an hour.

      Has anyone gotten sessions cookies to work in IE: that is a cookie set
      in IE without the date/time?

      Robert

      Comment

      • Dr John Stockton

        #4
        Re: Can't set session cookie???

        JRS: In article <410716B1.90806 06@PointedEars. de>, dated Wed, 28 Jul
        2004 05:00:01, seen in news:comp.lang. javascript, Thomas 'PointedEars'
        Lahn <PointedEars@nu rfuerspam.de> posted :[color=blue]
        >[color=green]
        >> var the_cookie = "wm_javascript= " + escape("SomeNam e|" + the_name);
        >> var the_date = new Date("December 31, 2050");[/color]
        >
        >Using date strings is error-prone because interpretation is
        >implementati on-dependent. Use several arguments instead:
        >
        > var the_date = new Date(2050, 11, 31);[/color]

        Which browsers do not understand new Date("December 31, 2050"); ?

        It is non-ISO numeric date strings that are unreliable; but "2050/12/31"
        should be safe everywhere, and is understandable by anybody; whereas
        some people think that December needs a Zed, or possibly a Zee, or
        transpose letters in it.

        In this case, "01/01/2051" could have been used.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
        Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
        PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
        Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

        Comment

        Working...