2011-11-29 59 views
1

請幫我解決我的代碼如何解決fsockopen錯誤?

$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 

有什麼問題嗎?

+1

可能重複的問題:[php_network_getaddresses:失敗的getaddrinfo:產品名稱或服務不知道(http://stackoverflow.com/questions/2661546/php-network-getaddresses -getaddrinfo-failed-name-or-service-not-known) – Wiseguy

+0

謝謝Wiseguy – Maroman

回答

4

使用fsockopen,只需要傳遞ip/hostname即可。

嘗試改變:

$fp = fsockopen("projecthoneypot.org/statistics.php", 80, $errno, $errstr, 5); 
// to 
$fp = fsockopen("projecthoneypot.org", 80, $errno, $errstr, 5); 

當你的HTTP請求的一部分,主持人:應該只projecthoneypot.org,不projecthoneypot.org/statistics.php。

$網址大概應該是/statistics.php

+0

剛剛投了票(因爲它是正確的答案) – symcbean

+0

你是一個偉大的人!非常感謝你drew010。問候 – Maroman