js cookie operations
Set cookie:
the document.cookie = 'key = value; Expires = expiration time';
Get cookie:
var cookie = document.cookie;
If you want to obtain a particular value, the string needs to process (remove the standard blasting)
Modify cookie, is to re-set
a the cookie
.
Delete cookie:
document.cookie = 'key = value; before the current time expires =';
php cookie operations
<?php
Set cookie: setCookie (key, value, validity);
Get the current timestamp time () in seconds
setCookie("uname","张三",time()+10);
Get cookie: $ _COOKIE
var_dump($_COOKIE["age"]);
Cookie package
Set cookie
function setCookie(key, value, indate) {
const time = +new Date() - 8 * 3600 * 1000 + indate * 1000;
document.cookie = `${key}=${value};expires=${time}`;
}
Get cookie
function getCookie(key) {
const cookieArr = document.cookie.split(';')
let value = '';
cookieArr.forEach(item => {
if (item.split('=')[0] === key) {
value = item.split('=')[1]
}
})
return value
}
Delete cookie
function delCookie(key) {
setCookie(key, "", -1);
}