本文介紹了如何為 uuid 設置 cookie的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個網站,每次加載/刷新頁面時都會生成一個 uuid.我想使用 cookie 使某個值在一段時間內保持不變.有誰知道可以幫助我的腳本?
I have a website which generates a uuid every time the page is loaded/refreshed. I want to make it so that a certain value remains the same for a period of time using cookies. Does anyone know of a script which can help me?
推薦答案
不確定你為什么要腳本,或者這里的問題是什么.要設置 cookie,只需使用:
Not sure why you are asking for a script, or what the problem here is. To set a cookie, just use:
if (empty($_COOKIE["uuid"])) {
$uuid = uniqid(); // or use a real UUID
setcookie("uuid", $uuid, time()+30*24*60*60, "/");
}
else {
$uuid = $_COOKIE["uuid"];
}
實際上,您應該偶爾執行一次 setcookie 以刷新 cookie 生存期.
Actually you should execute the setcookie once in a while and anyway to have the cookie lifetime refreshed.
這篇關于如何為 uuid 設置 cookie的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!