我对第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>
$ server必须是一个字符串,它似乎不是一个字符串。 $服务器如何初始化? –
$ server是查询的结果:$ query =“从whois where dominio ='”中选择服务器名称。$ dom [$ campi]。“'”; $服务器=的mysql_query($查询); –
你有没有得到正确的列的价值? $服务器必须是类似www.example.com –