Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to give some unique id to each anonymous user in django

I want to create a table(postgres) that stores data about what items were viewed by what user. authenticated users are no problem but how can I tell one anonymous user from another anonymous user? This is needed for analysis purposes.

maybe store their IP address as unique ID? How can I do this?

like image 549
Jahongir Rahmonov Avatar asked May 18 '15 07:05

Jahongir Rahmonov


1 Answers

I think you should use cookies.

When a user that is not authenticated makes a request, look for a cookie named whatever ("nonuserid" in this case). If the cookie is not present it means it's a new user so you should set the cookie with a random id. If it's present you can use the id in it to identificate the anonymous user.

like image 178
Ionut Hulub Avatar answered Sep 28 '22 07:09

Ionut Hulub