简体   繁体   中英

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

I have entity Post which contains userIp , this gives me information only about IP, I want to be able to differentiate between multiple users, even if they come from the same origin IP

Hope you understand what I need :D

You could try and use cookies, as I mentioned in my comment. Here is a simple example:

$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
}

This way, each user (well, to be exact, each browser installation) should be identifiable by its own cookie / unique ID.

As I mentioned, problems may arise anyway if users don't accept or delete cookies.

Also, you should have in mind, that in some countries a user has to explicitly give his consent that your site may store cookies (as often seen in a popup when the user enters the site for the first time).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM