Jump to content

Click button delay


sphinx

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.