what are cookies code example
Example 1: javascript create cookie
function setCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toUTCString();
}
document.cookie = name + "=" + (value || "") + expires + "; path=/";
}
function getCookie(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;
}
setCookie("user_email","[email protected]",30);
var userEmail=getCookie("user_email");
Example 2: cookies
So cookie is a rest request which basically
just like on the websites, used to store
some common information about where the
request originated. For example while end user
shop online once they view certain items
next time once they go to that website it
will suggest similar products.
Example 3: cookies
<?php setcookie('pseudo', 'M@teo21', time() + 365*24*3600); ?>
Example 4: cookies
<?php setcookie('pays', 'Chine', time() + 365*24*3600, null, null, false, true); ?>