Auciou posted on October 04, 2009 at 06:11
The program of preventing the spam and closing IP which designed by me, had been used for several months on ufoaq.com, the effect was very good, not only simple, but also highly effect, it is simpler than the program which designed by me in 2006. Generally, the program of preventing the spam was via that write the Cookies, the program of closing IP was via that write the Cookies and read the IP list from the database, this article will take PHP, for instance. Because this program needs to write the Cookies, please write <?ob_start();?> at the very head of the very outer of such as post.php, reply.php, submit.php, otherwise it will take error. The elements of program of preventing is as below, this program is written in the common module such as judge.php, this file is includeed by the other files with the include() function. <?$te=30; //You could set this value for the time which just can post for one time in 30 seconds, if omit $te=30;, the default value is 60. Then write Cookies in post.php, as below: The program of closing IP is below: <?$ip=$_SERVER["REMOTE_ADDR"];
if (!$te) $te=60;
$t9=time();
if ($t9-$_COOKIE[te]<$te) $kx.="The time between you post for 2 times should be more than ".$te." seconds, please post ".$te." seconds later.";
if ($kx) {……} //Take error to the poster, and the program will not run.
?>
<?if (!$kx) setcookie("te",$t9,$t9+$te,"/");?>
$i=…… //$i was the IP list which reed from the database, such as the value of $i is "125.33.125.255,133.134.99.1", many IPs are spaced out by comma, this value can be revised in the background of site. Because the configurations of background of site are different, this article will not explain the program which how to revise this value, please write the program by yourself. Because the program below uses the strpos() function, not uses the circle program to judge that whether the IP of user exists in the $i value, you may set for many IPs which you want to close, several hundred IPs will not affect the efficiency of program for much. While the user-side write the Cookies, the user's IP is closed completely, you may delete all the value of $i.
$j=$_COOKIE[pe];
$h="Your IP is closed.";
if ($j) $kx.=$h;
elseif (strpos($i,$ip)!==false){$kx.=$h;
if (!$j) setcookie("pe","50",time()+86400*9,"/");}
if ($kx) {……} //Take error to the poster, and the program will not run.
?>
Peaceful Seabed | My column
UFOAQ | ZJ7.COM
Category:
Program | Internet | Computer
Blog Research | PHP | Philosophy
Gratitude
Archives:
January 2010
December 2009 | October 2009 | September 2009 | April 2009
December 2008 | November 2008
May 2007 | April 2007
August 2005 | July 2005 | June 2005
May 2005 | April 2005 | March 2005
February 2005 | January 2005
The recent article:
Diary: 2010-01-15
Many Linux hostings do not support the mod_expires module
Figured out, there is still a way
About the delicated IP of IXWebHosting
About the QUERY_STRING parameter of URL
About the ping value and speed of site
The relation between program and .htaccess file
Saved a delicated IP
Judge that does a long-range file exist in PHP
How to call the Confederation of Planets and the high evolving beings of alien/pray/make a wish
Use Apache as the local virtual hosting to preview the Blog
Create the development environment of Apache
Reinstall Apache and PHP for one step
The elements of program of preventing the spam and closing IP
How to close the visit log of ixwebhosting
Happy Wedding to a friend
Make an easy Audio/Video converter
Every day is the curriculum in life
Make an easy audio converter
This Blog had been newly regulated