Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 05-23-2012, 01:15 PM Cookies
Skilled Talker

Posts: 90
Name: Lisa Forgan
Location: Colorado
Trades: 0
This has to be done by javascript due to specific client request.

I need to create a cookie for a webpage that remembers a user.
It should expire after 45 days.

Please help me out here.
I'm not sure if I'm on the right track here and I don't know how to test to see if this will work:

Code:
<script>
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}    

function eraseCookie(name) {
    createCookie(name,"",-1);
}

createCookie('ppkcookie','testcookie',42)
</script>

Last edited by Physicsguy; 05-24-2012 at 04:32 PM.. Reason: Code formatting
Puddlemut is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-25-2012, 05:40 AM Re: Cookies
miki86's Avatar
Extreme Talker

Posts: 239
Location: print_r($serbia);
Trades: 0
Quote:
Originally Posted by Puddlemut View Post
I don't know how to test to see if this will work:
How about decreasing the expire time to 60 seconds?

This addon for firefox can be usefull too:
https://addons.mozilla.org/en-US/fir...dl-mostpopular

Go to Cookies->View cookie information to see all cookies from that web page.
miki86 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Cookies
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13755 seconds with 11 queries