我找不到可用的 php 域可用性函数来检查域是否可用,然后定义一个可用或不可用的 $status 变量,以便我可以将其包含在我的消息中。
关于如何执行此操作有任何提示吗?我尝试过各种 native php 函数,如 getdnsrr 等,但无法让它们工作。我只需要将 $status 定义为可用或不可用。
感谢您的帮助。
最佳答案
谷歌结果
<?php
// Function to check response time
function pingDomain($domain){
$starttime = microtime(true);
$file = fsockopen ($domain, 80, $errno, $errstr, 10);
$stoptime = microtime(true);
$status = 0;
if (!$file) $status = -1; // Site is down
else {
fclose($file);
$status = ($stoptime - $starttime) * 1000;
$status = floor($status);
}
return $status;
}
?>
返回 ping 服务器所花费的时间。
http://www.tutcity.com/view/check-your-server-status-a-basic-ping.10248.html
要检查域是否可用:
<?php
function checkDomain($domain,$server,$findText){
// Open a socket connection to the whois server
$con = fsockopen($server, 43);
if (!$con) return false;
// Send the requested doman name
fputs($con, $domain."\r\n");
// Read and store the server response
$response = ' :';
while(!feof($con)) {
$response .= fgets($con,128);
}
// Close the connection
fclose($con);
// Check the response stream whether the domain is available
if (strpos($response, $findText)){
return true;
}
else {
return false;
}
}
?>
$status = checkDomain("stackoverflow.com",'whois.crsnic.net','No match for');
关于php 域名可用性函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1220484/