如何保存访客的uuid值
可能的重复:
如何为 uuid 设置 cookie
您好,这是我的网站,http://xblgenerator.co.cc 。每次加载页面时它都会生成一个随机 ID。我想制作一个脚本来保存返回用户的 id 生成器的输出。例如,如果用户访问我的网站,并获取此 id: http://xblgenerator.co.cc /id=12345 ,我希望用户在刷新/重新加载页面时看到相同的 id。也许这可以用cookie来完成,但我没有取得任何成功。这是我的 cookie 脚本,它不起作用,
setcookie('firstvisit', 1);
setcookie('uuid', $rnd_id, time()+368400);
if(isset($_COOKIE['firstvisit']) && isset($_COOKIE['uuid'])) {
// load uuid content
}
请不要回答我应该使用会话,因为我希望访问者的 id 在一个月内保持不变。我也不想使用数据库。有人可以告诉我上面的脚本中需要更改哪些内容,或者还可以做什么?谢谢。
Possible Duplicate:
How to set cookies for uuid
Hello here's my site, http://xblgenerator.co.cc . It generates a random id everytime the page is loaded. I want to make a script which saves the output if the id generator for a returning user. For example, if a user visits my site, and gets this id: http://xblgenerator.co.cc/id=12345 , i want the user to see that same id if he refreshes/reloads the page. Maybe this can be done with cookies, but i didn't have any success with it. Here's my cookie script which doesnt work,
setcookie('firstvisit', 1);
setcookie('uuid', $rnd_id, time()+368400);
if(isset($_COOKIE['firstvisit']) && isset($_COOKIE['uuid'])) {
// load uuid content
}
Please dont answer that I should use sessions because I want the id to remain the same for the visitor for a month. I don't want to use databases either. Can somebody tell me what to change in the script above, or what else to do? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保在设置之前检查cookie值,否则每次都会被覆盖,并且您将不知道用户的浏览器是否已经传入了现有的cookie。除此之外,这看起来是正确的。
Make sure you check the cookie value before setting it, otherwise it will be overwritten every time and you won't know if the user's browser has already passed in an existing cookie. Other than that, this looks correct.
您的网站似乎没有正确设置 cookie。我在那里,看到两个 cookie 1.firstvisit 和 2.uuid 。现在,uuid 具有您的脚本名称的值。您想要将生成的 ID 的值而不是脚本名称 (random_id.php)
的值中,
?>
You website doesn't seem to set the cookie right. I was there and I see two cookies 1.firstvisit and 2.uuid . Now, uuid has the value of your script name. You want to put the value of the generated ID NOT the script name (random_id.php)
as the previous answer states, don't set the cookie before checking it.
?>