Saving data on an "anonymous" user

I am currently working on developing a Symfony2 application that will not only accept user registrations, but allow visitors to go through almost the entire flow of the site without creating an account or logging in. Design ideas look something like this (suggestions / improvements are welcome):

  • When a user logs into his account, data will be saved for users / related objects as usual.
  • When an anonymous user first enters the site, an “anonymous user object” is created for them, as if they were registered, but with something like USER_<session_id> as an identifier instead of a personalized username. Any activity that they perform on the site is stored for this anonymous user object.
  • When an anonymous user decides to register, their anonymous user object is updated to the registered user object, saving their data for future use.
  • If an anonymous user leaves the site without registering, the anonymous user object must be cleaned up after a while to prevent the collection of dead data.

What is the best way to do this? In particular, what is considered “best practice” for creating / manipulating a user object for an anonymous user without the need to place code in each controller?

+6
source share
2 answers

I would advise against using an IP address for this, as this can cause problems for the users behind NAT. Using a custom cookie or sessionId cookie (PHPSESSID) as an identifier for tracking purposes would be a better idea. Google uses this strategy for its advertising. Stand on the shoulders of the giants!

+4
source

I have something similar to this that I had to do. What I did was compile an anonymous IP address of users (using ($ _SERVER ['REMOTE_ADDR'])). Then I used the IP address for tracking. You can then use this when they register to add your past to your newly created account.

Then you can simply run a simple query to remove any IP address that has not been active for some time (most users have dymanic IP addresses, so they will change every so often).

0
source

Source: https://habr.com/ru/post/887860/


All Articles