如何识别访问我的网站而未登录的客户端 [英] How to recognise a client visiting my site without being logged in

查看:59
本文介绍了如何识别访问我的网站而未登录的客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为电子商务网站构建购物车。我想知道如何跟踪未登录的用户。



我尝试了什么:



i尝试使用远程地址,但似乎正在改变用户

i am trying to build a cart for a ecommerce website. i want to know how can i keep track for user who are not logged in.

What I have tried:

i tried using remote addr but it seems to be changing for user

推荐答案

你根本不能信任IP地址:它们不仅可以改变(当用户在移动设备或笔记本电脑上移动时,或者当路由器被重置时),它们也被连接到单个路由器的所有用户共享 - 因此同一公司的所有员工都将共享相同的内容。 IP地址。



相反,使用cookie将跟踪ID或购物车存储在用户设备上 - 这样它与用户一起移动,他不会丢失它,他的购买不与其他用户共享。有很多信息可以通过Google提供示例代码: cookies php [ ^ ]
You can't trust IP addresses at all: not only can they change (as the user moves around on a mobile, or laptop, or when the router is reset), they are also shared by all users connected to a single router - so all employees at the same company would share the same IP address.

Instead, use cookies to store the tracking id or a shopping cart on the user device - that way it moves with the user, he doesn't lose it, and his purchases aren't shared with other users. There is loads of info complete with example code available via Google: cookies php[^]


简单:您使用 cookies [ ^ ]。


这篇关于如何识别访问我的网站而未登录的客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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