The easiest way to describe my problem with a working example: even if you are not logged in, YouTube remembers what you watched, and next time gives you recommendations based on the previous movies you watched.
My site looks like a way: users can vote for articles without logging in, and the site remembers votes with cookies. I figured out a working method, but there should be an easier way - also now using the DB is nothing but optimized.
Each visitor has a check if he has cookies. If so, then I ask for his vote. If not, I create a dummy user and send him cookies. Now I store this timestamp of the "last_visit" users. After that, everything is the same for both users. My problem is that my database is populated with dummy users, so I deleted my cookies after 3 months, and my site regularly checks which users have not visited my site in the last 3 months and removes them from the database.
I know that I have complicated this too much, but my voting system uses AJAX, and I could not find a method for sending cookies (and creating a dummy user) only if voting took place, and not every time a simple visitor browses my site - without the right to vote.
Also note: I insist on using cookies - I know that it would be easier to store IP addresses when voting, but there are schools, companies that use the same IP address, and I like to allow my users to use my site.
What am I missing here? How can this be optimized?
source
share