更新时间:2022-11-03 10:04:10
设置cookie非常容易.以我的经验,最简单的设置方法是通过 JQuery 插件:
Setting cookies is very easy. In my experience the simplest way to set them is through a JQuery plugin: jquery-cookie.
对于您的任务,您可以设置一个具有随机几乎唯一 ID的cookie(请检查
For your task you can set a cookie with a random almost-unique ID (check this question to know how) the first time the user open your website. For example
$.cookie('user_id', 'the_random_id');
当用户回来时,您可以读取该值
When the user come back you can read that value
user_id = $.cookie('user_id')
并在数据库中检查有关该用户的相对信息.
and check in your database the relative information about that user.
很明显,如果用户不接受cookie或将其删除,则无法识别他.
Obviously if an user does not accept cookies or deletes them you cannot identify him.