Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Location
    Gaborone, Botswana
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    cookie expiry date 2074?

    hi, i have the following script to set a cookie:



    <SCRIPT LANGUAGE="JavaScript"><!--
    function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
    ( (expires) ? ";expires=" + expires.toGMTString() : "") +
    ( (path) ? ";path=" + path : "") +
    ( (domain) ? ";domain=" + domain : "") +
    ( (secure) ? ";secure" : "");
    }
    var today = new Date();
    var zero_date = new Date(0,0,0);
    today.setTime(today.getTime() - zero_date.getTime());

    var todays_date = new Date(today.getYear()-71,today.getMonth(),today.getDate(),0,0,0);
    var expires_date = new Date(todays_date.getTime() + (52 * 7 * 86400000)); // 52 weeks

    var name = 'cookied';
    var value = '52477001';

    Set_Cookie(name,value,expires_date);
    document.write(expires_date);
    //--></SCRIPT>




    Yet, there seems to be a problem with the expiry date. It supposed to set it to the current time and date + the specified one. Now the problem is that it sets the xpiry date to midnight 2074... is it not possible to do this or is there a problem in the script layout?

    d52477001

  • #2
    New to the CF scene
    Join Date
    Jun 2003
    Location
    Gaborone, Botswana
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    really nobody has an idea?
    Last edited by d52477001; 06-07-2003 at 11:35 PM.

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Please try the following


    <SCRIPT LANGUAGE="JavaScript"><!--
    function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
    ( (expires) ? ";expires=" + expires.toGMTString() : "") +
    ( (path) ? ";path=" + path : "") +
    ( (domain) ? ";domain=" + domain : "") +
    ( (secure) ? ";secure" : "");
    }

    from="08/06/2003"
    to="08/06/2074"

    var fromArray = from.split('/');
    fromdate = new Date( fromArray[2], fromArray[1]-1, fromArray[0]);

    var toArray = to.split('/');
    todate = new Date( toArray[2], toArray[1]-1, toArray[0]);

    count=(todate-fromdate)/86400000

    var expires_date = new Date();
    expires_date.setTime(expires_date.getTime() + (count*24*60*60*1000));


    var name = 'cookied';
    var value = '52477001';

    Set_Cookie(name,value,expires_date);
    document.write(expires_date);
    //-->
    </SCRIPT>

  • #4
    New to the CF scene
    Join Date
    Jun 2003
    Location
    Gaborone, Botswana
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it seems that you have missunderstood my question. i want the cookie to expire after, say, 15 minutes. is this possible?

    d52477001

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Please try the following


    <SCRIPT LANGUAGE="JavaScript"><!--
    function Set_Cookie(name,value,expires,path,domain,secure) {
    document.cookie = name + "=" +escape(value) +
    ( (expires) ? ";expires=" + expires.toGMTString() : "") +
    ( (path) ? ";path=" + path : "") +
    ( (domain) ? ";domain=" + domain : "") +
    ( (secure) ? ";secure" : "");
    }

    time=15 // IN MINUTES

    var expires_date = new Date();
    expires_date.setTime(expires_date.getTime() + (time*60*1000));

    var name = 'cookied';
    var value = '52477001';

    Set_Cookie(name,value,expires_date);
    document.write(expires_date);
    //-->
    </SCRIPT>

  • #6
    New to the CF scene
    Join Date
    Jun 2003
    Location
    Gaborone, Botswana
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yep, that did it!

    thanks very much...

    d52477001


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •