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


How to check if there is more than one user after IP?

我有一个实体Post,它包含userIp,这只给我关于IP的信息,我希望能够区分多个用户,即使他们来自同一来源的IP

希望你能理解我的需求:D

正如我在评论中提到的,您可以尝试使用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(当用户第一次进入网站时,通常会出现弹出窗口)。