我是非常新的来自c#的php我目前正在为一个网站开发一个whois模块。我遇到的问题是当我浏览到我的php页面时它自动运行,发布消息"无效输入"在我点击按钮之前。为什么是这样?感谢您的帮助
..Php code to do lookup?>
<html>
<head>
<title>Whois Lookup Script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="whois.php">
<p>
<b><label for="domain">Domain/IP Address:</label></b>
<input type="text" name="domain" id="domain">
<input type="submit" value="Lookup">
</p>
</form>
<?php
if($domain) {
$domain = trim($domain);
if(substr(strtolower($domain), 0, 7) == "http://") $domain = substr($domain, 7);
if(substr(strtolower($domain), 0, 4) == "www.") $domain = substr($domain, 4);
if(ValidateIP($domain)) {
echo "hello before check";
$result = LookupIP($domain);
}
elseif(ValidateDomain($domain)) {
$result = LookupDomain($domain);
}
else die("Invalid Input!");
echo "<pre>\n" . $result . "\n</pre>\n";
}
?>
</body>
</html>
答案 0 :(得分:1)
您需要测试是否正在运行脚本以在第一次显示表单或由于提交表单而正在运行该表单。
提交表单时,<Animatable.View>
输入中的值将被放入domain
。因此,请检查是否已设置:
$_GET['domain']
答案 1 :(得分:1)
试试这个
<html>
<head>
<title>Whois Lookup Script</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="whois.php" method="POST">
<p>
<b><label for="domain">Domain/IP Address:</label></b>
<input type="text" name="domain" id="domain">
<input type="submit" value="Lookup">
</p>
</form>
<?php
$domain = $_POST['domain'];
if(!empty($domain)) {
$domain = trim($domain);
if(substr(strtolower($domain), 0, 7) == "http://") $domain = substr($domain, 7);
if(substr(strtolower($domain), 0, 4) == "www.") $domain = substr($domain, 4);
if(ValidateIP($domain)) {
echo "hello before check";
$result = LookupIP($domain);
echo "<pre>\n" . $result . "\n</pre>\n";
}
elseif(ValidateDomain($domain)) {
$result = LookupDomain($domain);
echo "<pre>\n" . $result . "\n</pre>\n";
}
else{
die("Invalid Input!");
}
}
?>
</body>
</html>