开发者

Only one outgoing link every 30 seconds

I'm working on a website now with a lot of external links. All links are going through a PHP file called: out.php

So a normal external link would be something like: out.php?url=http://www.google.com

My question is how to prevent people from clicking multiple links at a time? I want them to click only one link in 30 seconds for example. If they click another link an error should be appear telling them to wait the rest for the seconds, before they can visit another page.

Using cookies is not an option, because they still can disable the cookies.

Thanks in advance fo开发者_StackOverflow社区r any help!


Save the url which was clicked somewhere (file, database, ...) and the timestamp when it was clicked last time. Then for every click check the timestamp of the given url (if exists). If it is inside the 30 seconds windows ignore the request, otherwise use the request and update the timestamp field. If you need to separate it for each user as well save the IP (or userid if you have), too.


You can say that you need cookies in order to view the site
You can use session cookies:
if they view page A:

   if(!isset($_SESSION['A']))
       $_SESSION['A'] = time();
   else {
       if((time() - $_SESSION['A']) <= 30000){
            $_SESSION['A'] = time();
            die('YOU JUST WERE HERE 30 SECONDS AGO! TRY AGAIN LATER!');
       }
   }
   $_SESSION['A'] = time();

Or something like that, the above code is not perfected

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜