Detecting if user has entered contest on html site
I have a soccer website that will have 6 little buttons that when clicked it will go through a random array and tell the user has won something, or not. What would be the best way to prevent the us开发者_Go百科er from clicking several times until the user won. For example some kind of javascript to detect the users ip and check if it has been in the site in the pasted x hours.
Thanks,
JavaScript can't detect your IP address. That is done when the webserver serves content to the browser.
You'd have to implement that functionality serverside (via PHP, etc.) and submit a POST
request via JavaScript (AJAX) when the person clicks the button. If the person with that IP has submitted within a certain timeframe, then just send back a nasty message accusing the person of cheating ;)
It's virtually impossible to stop people from cheating, but that will thwart many of them.
You're not really going to be able to do that in Javascript. You probably want an HTML form that submits to a server, and process that on the server, not in the browser.
It all depends on how you achieve it. If you tell the user for example that once they won, they have to enter a valid e-mail address to validate their win, it will stop a lot of people from doing it twice as most people only have 1 E-mail address. You can then combine it with an IP logger to check if the user has already tried. All of this is of course either HTML + PHP or AJAX + PHP.
精彩评论