我對第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 –