PHP implementation of IP features [original]_php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.