sphinx Posted October 16, 2011 Share Posted October 16, 2011 Hello there, I was wondering what coding would be required to block users from clicking/viewing content. My idea was only to allow people to request songs every 2 minutes. would I use PHP for this in terms of the request form template which is: <?php $song = file_get_contents('http://site.com/song.php'); if(!empty($song)) { header('Location: song-requests-interface.php'); } else { header('Location: offline.html'); } ?> Or would I use JS. The trouble is, I'm unsure if JS would be able to remember the users details. They could easily refresh the page. Many thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 16, 2011 Share Posted October 16, 2011 You will need to store a timestamp whenever a user makes a request. Then on each request check if the last timestamp is > 2 minutes. If you are using a system where users have to sign-in then store the timestamp in the user record in your database. If you are not using a login system then you could either store the value in a cookie or in a database according to the user's IP address. Each has its drawbacks. A cookie system can be easily avoided by the user if they so choose by deleting the cookie. Or they may have their security settings such that they won't accept a cookie. A server-side solution has the drawback in that just storing the IP address will prevent users behind a NAT from being able to access a file until 2 minutes after the last person on the same subnet. In other words, they all share the same 2-minute period. Quote Link to comment Share on other sites More sharing options...
sphinx Posted October 16, 2011 Author Share Posted October 16, 2011 Ok thanks, cookies is the way to go, don't worry about deleting, its only two minutes I just didnt know cookies can store for 2 minutes. Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 17, 2011 Share Posted October 17, 2011 Cookies will last as long as you set them to last (or until the user deletes them). If you go this route then you just need to set the cookie with a 2 minute expiration. Then you only need to see if the cookie exists. If no, allow user to access the file. If yes, do not allow access Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.