如何检查IP后是否有多个用户?

时间:2016-04-09 12:37:11

标签: php symfony

我有包含userIp的实体帖子,这只提供了有关IP的信息,我希望能够区分多个用户,即使它们来自同一个来源IP

希望你明白我的需要:D

1 个答案:

答案 0 :(得分:0)

我可以尝试使用Cookie,正如我在评论中提到的那样。这是一个简单的例子:

$userId = $request->cookies->get('userIdCookie');

//Set the cookie, if not present already
if (!$cookie) {
  $uniqueString = uniqid();
  $cookie = new Cookie('userIdCookie', $uniqueString);
  $response = new Response();
  $response->headers->setCookie($cookie);
  //Save the $uniqueString where you need it
}

这样,每个用户(确切地说,每个浏览器安装)都应该可以通过自己的cookie /唯一ID进行识别。

正如我所提到的,如果用户不接受或删除cookie,可能会出现问题。

另外,您应该记住,在某些国家/地区,用户必须明确同意您的网站可以存储Cookie(当用户第一次进入网站时,通常会在弹出窗口中看到)。

相关问题