Home > Backend Development > PHP Tutorial > php gets the client IP address code

php gets the client IP address code

高洛峰
Release: 2016-11-29 16:18:49
Original
1109 people have browsed it

//开源代码 

 

function getip(){  

             if (getenv("http_client_ip") && strcasecmp(getenv("http_client_ip"), "unknown"))  

$ip = getenv("http_client_ip"); //开源  

             else if (getenv("http_x_forwarded_for") && strcasecmp(getenv("http_x_forwarded_for"), "unknown"))  

$ip = getenv("http_x_forwarded_for"); //  

             else if (getenv("remote_addr") && strcasecmp(getenv("remote_addr"), "unknown"))  

$ip = getenv("remote_addr");  

             else if (isset($_server[@#remote_addr@#]) && $_server[@#remote_addr@#] && strcasecmp($_server[@#remote_addr@#], "unknown")) 

 

// 

 

$ip = $_server[@#remote_addr@#];  

else  

$ip = "unknown";  

             return($ip);  

}  

?> 

 

判断邮箱地址  

function checkemail($inaddress)  

{  

return (ereg("^([a-za-z0-9_-])+@([a-za-z0-9_-])+(.[a-za-z0-9_-])+",$inaddress));  

} //phpfensi.com 

?> 

 

function getip() { //获取ip  

if ($_server["http_x_forwarded_for"])  

$ip = $_server["http_x_forwarded_for"]; //  

    else if ($_server["http_client_ip"])  

$ip = $_server["http_client_ip"];  

    else if ($_server["remote_addr"])  

$ip = $_server["remote_addr"]; //  

    else if (getenv("http_x_forwarded_for"))  

$ip = getenv("http_x_forwarded_for");  

    else if (getenv("http_client_ip"))  

$ip = getenv("http_client_ip"); //  

    else if (getenv("remote_addr"))  

$ip = getenv("remote_addr");  

    else  

$ip = "unknown";  

    return $ip;  

}  

?> 


Related labels:
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template