Home  >  Article  >  Backend Development  >  php获取到两个ip解决方法

php获取到两个ip解决方法

WBOY
WBOYOriginal
2016-06-13 12:37:39778browse

php获取到两个ip
下面是使用fsockopen伪造ip。

	  
$out = "POST $path HTTP/1.1\r\n";
$out .= "Accept: */*\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
$out.="X-Forwarded-For: ".$ip."\r\n"; //主要是这里来构造IP
$out .= "Host: ".$domain_ip."\r\n";
$out .= "Content-Length: ".$content_length."\r\n";
$out .= "Connection: close\r\n\r\n";
$out .= $content."\r\n\r\n"; //提交的内容

这个是获得客户端ip。本地可以获得伪造的ip,服务器上获得却是两个ip。比如变成这样116.7.54.78, 27.151.95.121。求帮忙

if (getenv("HTTP_X_FORWARDED_FOR"))
{
$ip = getenv("HTTP_X_FORWARDED_FOR");
}
elseif (getenv("HTTP_CLIENT_IP"))
{
$ip = getenv("HTTP_CLIENT_IP");
}
elseif (getenv("REMOTE_ADDR"))
{
$ip = getenv("REMOTE_ADDR");
}
else
{
$ip = "";
}

Statement:
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