PHP:fsockopen()期望参数1为字符串

时间:2016-01-31 22:59:34

标签: php html html5 sockets

我遇到第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 
    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>

1 个答案:

答案 0 :(得分:0)

您有服务器作为查询,但您尚未指定结果。

然后你需要mysql_fetch_assoc来获取一个值。

 $s =mysql_query($query);
 while ($row = mysql_fetch_assoc($s)) {
     $server = $row['servername'];
 }

您还应该认真考虑使用mysqli或pdo。 php mysql query documentation