Published 1 month ago by behnampmdg3
How would you tackle this issue:
When a visitor hits the page, load a countdown timer that shows X days, hours and minutes before expiring. When the visitor returns, the timer should be set from the time visitor first visited the page.
When that page gets reloaded, I query the database, if the IP exists, instead of creating the record, I load the countdown timer associated with that id, calculate the time since created, and load the countdown accordingly.
IP isn't really a good solution, especially in today's mobile world, where someone might access a site from their home (1 ip), their mobile (a different ip), some public wifi (another ip), their office (another ip), etc.
I'd say that the vast majority of the general public doesn't use private browsing. Just people who know better, like us geeks.
There isn't going to be a 100% foolproof solution. They all have drawbacks. But I think the chances of a users IP changing is a lot higher than the people who use private browsing.
if just the time, visitor can edit the cookie
Sure, but how many people in the
general public do you think would actually do that, or even know how to do it? 99.99% of people don't even know there's a console or developer tools in their browser, even if they've been using it for 20 years. Most people aren't coders or understand how the web actually works. They just know how to use their browser.
I can mask my ip, or use a friends computer with a different ip, or use a VPN to use a different IP too, if I really wanted to get around something. But again, would the general public?
Every solution has drawbacks. What you want is the thing that will work in the vast majority of cases. Not all cases. That's impossible.