2015-07-10 186 views
-1

是否可以使用用户的当前IP地址作为PHP cURL的代理地址?目前,我正在尝试下面的代码,但提出请求超时错误。我用hma代理测试它工作正常,但是当我尝试使用用户的IP地址时,它在服务器日志中发出请求时间错误。如何在PHP cURL中使用用户的当前IP地址作为代理?

function get_page($url){ 

$proxy=$_SERVER['REMOTE_ADDR'].":80"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_PROXY, $proxy); 
curl_setopt($ch, CURLOPT_HEADER, 0); // return headers 0 no 1 yes 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return page 1:yes 
curl_setopt($ch, CURLOPT_TIMEOUT, 40); // http request timeout 20 seconds 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects, need this if the url changes 
curl_setopt($ch, CURLOPT_MAXREDIRS, 2); //if http server gives redirection responce 
curl_setopt($ch, CURLOPT_USERAGENT, 
    "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7"); 
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // cookies storage/here the changes have been made 
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // false for https 
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); // the page encoding 

$data = curl_exec($ch); // execute the http request 
curl_close($ch); // close the connection 
return $data; 
} 

有很多活的例子是做同样的。例如从谷歌

这两个工具
  1. google.com/gwt/x
  2. developers.google.com/speed/pagespeed/insights
+0

你为什么要这么做?您假定在用户计算机的端口80上存在运行的http代理。 – PiX06

+0

这就是问题所在,我无法做出决定。我知道这是可能的,但我怎么不知道这一点。 – Disk01

+0

如果想了解一下您在此尝试实现的内容,那么我们可以提供其他选项,这将是一件好事。 – PiX06

回答

0

不可能的。虽然您可以使用用户的IP作为“源”使您的服务器发出SYN数据包,但是来自目标计算机的任何回复数据包都将传送到用户的计算机,而不是您的服务器。

除非您控制目标/受害者上游的网络基础设施,否则无法欺骗完整的TCP连接。