2

I've been out of web development for a while now so very rusty. I need to make a cookie

  1. If the user visits the site > set cookie
  2. If user comes back to site > read cookie
  3. If time since user last arrived is less than 24hrs > set the ID of a div to style="display:none;"

im struggling and would really appreciate some guidance.

thanks so much

2
  • What language are you looking to implement this in? Server side, or JavaScript? Commented Jan 28, 2010 at 2:52
  • javascript thanks code duck... just trying to keep it real simple Commented Jan 28, 2010 at 4:30

2 Answers 2

1

With JavaScript you can
- read cookie:

var coo = [],
    a;
if(document.cookie != ''){
    $.each(document.cookie.split('; '), function(i, val){
        a = val.split('=');
        coo[a[0]] = a[1];
    });
}

here we have a coo with all cookies (coo['Cookie1'] == 'value').
- set cookie:

document.cookie = 'Cookie_1='+'value for this cookie';

BTW code is using jQuery for $.each.

Sign up to request clarification or add additional context in comments.

Comments

0

Heres the messy solution i cam up with in case anyone wanted to know:

function nameDefined(ckie,nme)

{ var splitValues var i for (i=0;i tvalue=getCookieValue(nvpair,cname) //Gets the value of the cookie if (tvalue == cvalue) return true else return false } else return false } function redirectLink() { if (testCookie("here10", "yes")) { //window.location="here.html" //Go to the location indicating the user has been here //alert("there"); window.document.getElementById("indicator").style.display = "none"; } else{ //alert(" not there"); var futdate = new Date() //Get the current time and date var expdate = futdate.getTime() //Get the milliseconds since Jan 1, 1970 expdate += 10000 //expires in 1 hour(milliseconds) futdate.setTime(expdate) var newCookie="here10=yes; path=/;" //Set the new cookie values up newCookie += " expires=" + futdate.toGMTString() window.document.cookie=newCookie //Write the cookie // window.location="not.html" //Go to the location indicating the user has not been here

  window.document.getElementById("indicator").style.display = "block";

} }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.