2008-01-24 00:00:00
//
This article from the original site: www.drise.cn
Author: www.drise.cn
Reprint please specify: from www.drise.cn
qq:271728967
//
Get up early and suddenly see, my site someone is disgusting, in order to prevent this kind of thing I think of a way that is the IP of the user.
Home we will build the database:
CREATE TABLE ' Su_lockip ' (
' ID ' int (4) not NULL auto_increment,
' Lockip ' varchar (1024x768) Default NULL,
PRIMARY KEY (' id ')
)
Next page to create a file-based page, mainly the user writes the IP to "|" Separate, this page is not much to write, I will simply write, the storage code $ulockip=$_post[' z ']?$_post[' z ': ';
if (empty ($UlockIp)) {
Exit ("");
}
$sql = "Update su_lockip set lockip= ' $UlockIp '";
if (mysql_query ($sql)) {
Exit ("");
}else{
Exit ("");
}
It's that simple, and finally it's locked up. The following code is based on whether the user IP is stored in the data, if the prompt was killed. The code is as follows:
function Lock_user_ip () {
$Usql =mysql_query ("SELECT * from Su_lockip");
$Urs =mysql_fetch_array ($Usql);
$UlockIp = $Urs [' Lockip '];
$ClockIp = $this->get_real_ip ();
$Iplist =explode (' | ', $UlockIp);
if (In_array ($ClockIp, $Iplist)) {
Exit (' Sorry system lock your IP ');
}
}
function Get_real_ip () {//This piece of code comes to the Internet.
$ip =false;
if (!empty ($_server["Http_client_ip")) {
$ip = $_server["Http_client_ip"];
}
if (!empty ($_server[' http_x_forwarded_for ')) {
$ips = Explode (",", $_server[' http_x_forwarded_for ');
if ($IP) {array_unshift ($ips, $ip); $ip = FALSE;}
for ($i = 0; $i < count ($ips); $i + +) {
if (!eregi ("^ (10|172\.16|192\.168) \.", $ips [$i])) {
$ip = $ips [$i];
Break
}
}
}
Return ($ip $ip: $_server[' remote_addr ');
}
Haha finished is so simple, no security filtering processing.
http://www.bkjia.com/PHPjc/631849.html www.bkjia.com true http://www.bkjia.com/PHPjc/631849.html techarticle 2008-01-24 00:00:00//This article from the original site: www.drise.cn Author: www.drise.cn reprint please specify: from www.drise.cn qq:271728967//early morning together suddenly see, My website someone is in a nasty mess ...