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

php获取到两个ip解决方法

WBOY
Release: 2016-06-13 12:37:39
Original
918 people have browsed it

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

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

这个是获得客户端ip。本地可以获得伪造的ip,服务器上获得却是两个ip。比如变成这样116.7.54.78, 27.151.95.121。求帮忙
<br />
      if (getenv("HTTP_X_FORWARDED_FOR")) <br />
	{ <br />
		$ip = getenv("HTTP_X_FORWARDED_FOR"); <br />
	} <br />
	elseif (getenv("HTTP_CLIENT_IP")) <br />
	{ <br />
		$ip = getenv("HTTP_CLIENT_IP"); <br />
	} <br />
	elseif (getenv("REMOTE_ADDR"))<br />
	{ <br />
		$ip = getenv("REMOTE_ADDR"); <br />
	} <br />
	else <br />
	{ <br />
		$ip = ""; <br />
	} <br />
Copy after login

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template