如何设置uuid的cookie [英] How to set cookies for uuid

查看:472
本文介绍了如何设置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。这可以用作用户何时重新访问站点的信号。在每个页面上存储一个uuid cookie将会给你最后一个uuid,从中你可以做你想要的。

You can set a cookie that's deleted when the browser session closes. That can be used as a signal for when the user is "revisiting" the site. Storing a uuid cookie on each page will then give you the last uuid from which you can do what you were requesting.

setcookie('firstvisit', 1);
setcookie('uuid', $uuid, time()+368400);
if(isset($_COOKIE['firstvisit']) && isset($_COOKIE['uuid'])) {
    // load uuid content
}

这篇关于如何设置uuid的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆