【问题标题】:How to fix fsockopen error?如何修复 fsockopen 错误?
【发布时间】:2011-11-29 17:20:28
【问题描述】:

请帮我修复我的代码

$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

请问有什么问题?

【问题讨论】:

标签: php fsockopen


【解决方案1】:

使用 fsockopen,您只需传递 ip/主机名。

尝试改变:

$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

【讨论】:

  • 刚刚投了赞成票(之前有人投了反对票),因为这是正确答案
  • 你是个伟人!!非常感谢draw010。问候
猜你喜欢
  • 1970-01-01
  • 2015-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-04
  • 2016-11-17
  • 2011-07-24
  • 2021-05-10
相关资源
最近更新 更多