2016-01-31 74 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 –

相关问题