Home > Article > Backend Development > php获取到两个ip解决方法
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 />
<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 />