Discussion Locked

JavaScript - Limit visits to a Webpage

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Need to allow a user to view a webpage no more
than 3 times in a 24 hours period. Any thing over
that would direct them to a "Try again tomorrow" page. Would have to reset each day.

5 replies

by jay eckles

Much better to do something on the server side than something on the client side with Javascript. If you try a Javascript solution, the user only has to turn off Javascript or perhaps fiddle with your code to get into the site a fourth time. Also,how will you be able to distinguish among users? A cookie? What if the user goes to another computer or just deletes your cookie?

Create a login system where each user has a unique user ID and password, then control access using that system. Limit the logins to three per 24 hour period.

Jay

by parkin_thom

I agree that SERVER-SIDE manipulation is the best way to approach this problem.
However, if you do not have the flexibility and must use Javascript I can offer a solution.
Simply write a cookie on the user's system with an expiration of midnight today. Read that cookie when the site is visited and update it with the number of visits. (increment a counter value)
Then you can easily control the 'cutoff' point. You could even vary the number for different users by creating a different cookie from different pages of the web site.

THOM
twice21.com

This discussion is closed to new replies.