Calendar

2008年十月
« 九   十一 »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Translator

php防止恶意访问小程序

本来写PAYPAL IPN response 时用来防止反复尝试的函数,保护性很差,后来改成原地址审核($hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);if(!preg_match(‘/paypal\.com$/’, $hostname)) {…..),所以个就弃用了。在删之前记录不来,应该有更好的算法,不知道谁有研究。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
if (!avoid_refresh ('15')) die ("Hacking Attempt!!");
.....
.....
.....
function avoid_refresh ($time){
	session_start();
  if (isset($_SESSION["post_sep"])) {
      if (time() - $_SESSION["post_sep"] < $time)  {
      	$_SESSION["post_sep"] = time();
        return false;
      } else {
          $_SESSION["post_sep"] = time();
          return true;
      }
  } else {
      $_SESSION["post_sep"] = time();
      return true;
  }
}

Leave a reply

  1. You will post the following soon.
    Go ahead and start typing.