Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 通过其IP地址获取远程网页内容&;HTTP主机头?_Php - Fatal编程技术网

Php 通过其IP地址获取远程网页内容&;HTTP主机头?

Php 通过其IP地址获取远程网页内容&;HTTP主机头?,php,Php,我想通过网页的IP地址获取网页内容。还有许多其他网站也共享此IP,因此使用HTTP主机头。 此PHP web服务器没有DNS服务,将响应 file_get_contents("http://allaboutcircuits.com"); 借 从几个例子中,我尝试: $context = stream_context_create(array('http' => array('header' => 'Host:allaboutcircuits.com'))); $url = 'htt

我想通过网页的IP地址获取网页内容。还有许多其他网站也共享此IP,因此使用HTTP主机头。 此PHP web服务器没有DNS服务,将响应

file_get_contents("http://allaboutcircuits.com");

从几个例子中,我尝试:

$context = stream_context_create(array('http' => array('header' => 'Host:allaboutcircuits.com')));
$url = 'http://68.233.243.63';
echo file_get_contents($url, 0, $context);
而且我似乎在file_get_contents()的行中仍然有相同的错误,这意味着file_get_contents()仍然在DNS中查询主机头,尽管是提供的IP地址。

如何修复此代码

$s=socket_create(AF_INET,SOCK_STREAM,SOL_TCP); 
socket_connect($s,'68.233.243.63',80);
socket_send($s,"GET / HTTP/1.1\r\nHost: www.allaboutcircuits.com\r\n\r\n",1000,0);
socket_recv($s, $buf, 100000,0);
socket_close($s);
echo $buf;
这应该是一个开始


这应该是一个开始

问题是,该网站响应重定向到
www.allaboutcircuits.com
,因此PHP试图遵循重定向。将主机标题更改为包含
www.
前缀,它应该可以工作。

问题是,网站响应重定向到
www.allaboutcircuits.com
,因此PHP正在尝试遵循重定向。将主机标题更改为包含
www.
前缀,它应该会起作用。

您的问题已迁移到。这略有不同。这个问题告诉他如何使用主机标题,但这个问题是由他在尝试执行他们建议的操作时遇到的问题引发的。您的问题已迁移到。这略有不同。这个问题告诉他如何使用主机标题,但这个问题是由他在尝试执行他们的建议时遇到的问题引发的。哦,天哪!谢谢你,巴尔马!我能说什么:)哦,天哪!谢谢你,巴尔马!我能说什么:)一个输入错误的结果是$buf,而不是$resAfter套接字连接,我们如何获取网页内容?一个输入错误的结果是$buf,而不是$resAfter套接字连接,我们如何获取网页内容?
$s=socket_create(AF_INET,SOCK_STREAM,SOL_TCP); 
socket_connect($s,'68.233.243.63',80);
socket_send($s,"GET / HTTP/1.1\r\nHost: www.allaboutcircuits.com\r\n\r\n",1000,0);
socket_recv($s, $buf, 100000,0);
socket_close($s);
echo $buf;