如何为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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定您为什么要求脚本,或者这里的问题是什么。要设置 cookie,只需使用:
实际上,您应该偶尔执行 setcookie 一次,无论如何都要刷新 cookie 生命周期。
Not sure why you are asking for a script, or what the problem here is. To set a cookie, just use:
Actually you should execute the setcookie once in a while and anyway to have the cookie lifetime refreshed.
您可以设置一个在浏览器会话关闭时删除的 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.