请帮我修改我的代码
$fp = fsockopen("projecthoneypot.org/statistics.php", 80, $errno, $errstr, 5);
if ($fp) {
$url = "/";
fputs($fp, "GET $url HTTP/1.1\r\nHost: {projecthoneypot.org/statistics.php}\r\nConnection: close\r\n\r\n");
$resp = '';
while(!feof($fp)) {
$resp .= fgets($fp, 1024);
}
echo "$resp";
}
我总是收到此错误
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/xxx/public_html/xxx.php on line 3
Warning: fsockopen() [function.fsockopen]: unable to connect to projecthoneypot.org\statistics.php:80 (php_network_getaddresses: getaddrinfo failed: Name or service not known) in /home/xxx/public_html/xxx.php on line 3
请问有什么问题?
答案 0 :(得分:4)
使用fsockopen,您只需要传递ip / hostname。
尝试更改:
$fp = fsockopen("projecthoneypot.org/statistics.php", 80, $errno, $errstr, 5);
// to
$fp = fsockopen("projecthoneypot.org", 80, $errno, $errstr, 5);
作为HTTP请求的一部分,Host:应该只是projecthoneypot.org,而不是projecthoneypot.org/statistics.php。
$ url应该是/statistics.php