I need a script like this for my One Time Offer page. I already added a timer to that page which tells customers that the offer expires in 30 minutes. But they can still come back to that page because there's nothing there to block their IP addresses after the 30 minutes is up.
Use cookies and check the time the cookie was set - more than 30 minutes ago? offer is withdrawn. Most users aren't smart enough to clear the cookies or change browsers. If someone is really determined they'll get past your best efforts so keep it simple and you'll stop most in their tracks.
Or store a quick overview of a combination of browser info, IP-address and other characteristics of the user in the database, and check to see if there's a match - more secure than just a cookie (you can of course store a cookie as well and check for that first, but if not found, you can also check the database).
Yeah, scripttardery ain't gonna cut it. Scripting can be slapped aside with ridiculous ease, and many people browse with it disabled on purpose. Might I ask why you don't just store the IP, and MAYBE the UA string server-side? Of course, this is why MANY "one time offers" even if free track the user by validating a CC number or using IP + e-mail address verification.... but again that's ALL server-side and not JavaScript.
Do it in PHP instead. I saw this one on stackoverflow not too long ago while looking for something similar: <?php if(!isset($_COOKIE['visited'])){ setcookie('visited',true, time()+3600*24);// Save a cookie for 1 day echo '<div class="your_div">Your awesome offer goes here...</div>';} ?> Code (markup):
You can start the offer div/container with display=none css. Once the page is viewed, check for the cookie, if the cookie is not set change the display = inline and add the cookie. This will only show the offer on first load and you won't need server side scripting. However, server side scripting is more appropriate for such actions.
Except that only using a cookie is trivial to get past - delete the cookie, and you can use the one-time offer again, if need be. Depending on the type of offer, this might not matter that much, of course, but still... depending on only a cookie isn't really smart.