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
- Is this good to use Cookie?
- How to save multiple ids?
- How to retrieve all ids saved/stored in cookie?
- 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);