2016-01-31 72 views
0

我對第10行有一個問題($ f = fsockopen($ server,43,$ ae_whois_errno,$ ae_whois_errstr,AE_WHOIS_TIMEOUT);)。當我在輸入字段中寫入URL時會發生警告:「警告:fsockopen()期望參數1是字符串,在第10行的C:\ xampp \ htdocs \ Client-Server \ whoisclient.php中給出的資源。這是代碼。PHP:fsockopen()期望參數1爲字符串

<?php 
    include("preliminari.php"); 
    function ae_whois($query, $server) 
    { 

     define('AE_WHOIS_TIMEOUT', 15); // connection timeout 
     global $ae_whois_errno, $ae_whois_errstr; 

     // connecting 
     $f = fsockopen($server, 43, $ae_whois_errno, $ae_whois_errstr, AE_WHOIS_TIMEOUT); 
     if (!$f) 
      return false; // connection failed 

     // sending query  
     fwrite($f, $query."\r\n"); 

     // receving response 
     $response = ''; 
     while (!feof($f)) 
      $response .= fgets($f, 1024); 

     // closing connection 
     fclose($f); 

     return $response; 
    } 
    ?> 
    <html> 
    <head> 
    <title>Whois client con i socket del PHP</title> 
    <style type="text/css"> 
    .body { 
     font-family: Verdana, Geneva, sans-serif; 
    } 
    .titolo { 
     font-family: Verdana, Geneva, sans-serif; 
     font-weight: bold; 
     text-decoration: underline; 
    } 
    </style> 
    </head> 
    <body> 
    <?php 
    $indirizzo = $_GET['dominio']; 
    $dom = explode(".",$indirizzo); 
    $campi = count($dom)-1; 
    $query = "select servername from whois where dominio = '".$dom[$campi]."'"; 
    $server = mysql_query($query); 
    if (isset ($indirizzo)) { 
     $reply = ae_whois ($indirizzo, $server); 
     $reply = nl2br ($reply); 
     echo "<p>$reply</p>"; 
    } 
    ?> 
    <h2 align="center" class="titolo">Whois di un dominio</h2> 
    <form name="ricerca" method="get" action="whoisclient.php"> 
    <p align="center" class="body">Nome del dominio</p> 
    <p align="center" class="body"> 
     <input name="dominio" type="text"> 
    </p> 
    <p align="center" class="body"><input name="go" type="submit" value="WHOIS"></p> 
    </form> 
    </body> 
    </html> 
+0

$ server必須是一個字符串,它似乎不是一個字符串。 $服務器如何初始化? –

+0

$ server是查詢的結果:$ query =「從whois where dominio ='」中選擇服務器名稱。$ dom [$ campi]。「'」; $服務器=的mysql_query($查詢); –

+0

你有沒有得到正確的列的價值? $服務器必須是類似www.example.com –

回答

0

你有服務器作爲查詢,但你沒有指定結果。

然後你需要mysql_fetch_assoc來獲得一個值。

​​

您應該認真考慮使用mysqli或pdo來代替。 php mysql query documentation

+0

我已經實現了該解決方案,但現在當我寫「www.arduino.cc」之類的結果輸出爲「No匹配「WWW.ARDUINO.CC」 –

+0

並且該域名實際上已經在您的數據庫中了嗎? –

+0

與www.youtube.com –

相關問題