How to make records favorites

67 views Asked by At

I have a list of stores on my website.I want users to make stores their favorite.I am not asking them to login & I am not saving in database.

I want to save store ids in cookie for an year. I have this code.

function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+d.toGMTString();
document.cookie = cname + "=" + cvalue + "; " + expires;
} 



function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
    var c = ca[i].trim();
    if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
}
return "";
}

I want to save each store id and then retrieve them.My questions are

  1. Is this good to use Cookie?
  2. How to save multiple ids?
  3. How to retrieve all ids saved/stored in cookie?
  4. DO i need to append it to existing cookie?

This code will give me all cookies,I need to get only store ids i saved in cookie.

print_r($_COOKIE);
0

There are 0 answers