讀取cookie
在javascript中讀取cookie:
console.log(document.cookie)
;寫入cookie
document.cookie='key=value';
cookie的參數
新增參數的方法是用分號做區隔
user:macaron;path=/
Domain
、path
:設定cookie的使用範圍expires
、Max-Age
:設定cookie的使用期限HttpOnly
、secure
、SameSite
:設定cookie安全性Domain:
domain=macaron.com
path:
path=/admin
domain=macaron.com
,path=/admin
,那macaron.com/admin
、子路徑如macaron.com/admin/file
都是可以存取此cookie的,但是macaron.com
、macaron.com/home
則是無法存取的path=/
,是為了讓全站都可以存取此cookieexpires:
cookie=value;expires=True,22 May 2050 10:10:01 GMT
max-age:
cookie=value;max-age=4800
httponly:
secure:
samesite: