1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Javascript Set Cookie time to expire minutes from now

Discussion in 'JavaScript' started by cloudnthunder, Jul 10, 2010.

  1. #1
    Hi what is the code for javascript cookie to expire like 30 minutes from now? I tried the Date.setTime() function but it couldn't work.
    SEMrush
     
    cloudnthunder, Jul 10, 2010 IP
    SEMrush
  2. netload

    netload Member

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #2
    Try to use -1
     
    netload, Jul 10, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
  4. cloudnthunder

    cloudnthunder Peon

    Messages:
    163
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    ok i got it set up.

    anyway the cookie i set in javascript cannot be deleted in php. They both have the same name. Any idea what's wrong?
     
    cloudnthunder, Jul 10, 2010 IP
  5. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm not sure but I think that since PHP and javascript are different coding languages they might not use the same cookie names or folder. What are you trying to do exactly?
     
    Imozeb, Jul 11, 2010 IP
  6. netload

    netload Member

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #6
    Nice joke. Cookie save in browsers (Internet Explorer, etc.) and don't depend from programing language.

    cloudnthunder, print here your javascript and php code.
     
    netload, Jul 11, 2010 IP
  7. Logic Ali

    Logic Ali Active Member

    Messages:
    170
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #7
     
    var dt = new Date(), expiryTime = dt.setTime( dt.getTime() + 1800000 );
    
    document.cookie = 'myCookie=' + myValue + ';expires=' + dt.toGMTString();
    Code (markup):
     
    Logic Ali, Jul 11, 2010 IP
  8. netload

    netload Member

    Messages:
    105
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #8
    This code should delete your cookie
    setcookie ("myCookie", '', -1);
    PHP:
     
    netload, Jul 11, 2010 IP