我在互联网上发现了一个现有的脚本,它从WHOIS服务器获取数据并提取相关数据(例如,到期日期、状态)。由于它被长期抛弃,我一直在修改它,并创建了自己的CCD_,我遇到的问题是,我有一个whois.php文件,我想从MySQL数据库中获取一个域列表,并尝试使用(file_get_contents到我的script.php和foreach)提取每个域的Expiry/Status数据,然后用相关信息更新数据库。我很确定,除了"Foreach"&"File_get_contents"部分正确,因此我的脚本遇到错误。
"警告:第39行/home/user/public_html/mydomain.com/domains/whois.php中为foreach()提供的参数无效"
是我收到的错误。
whois.php:的代码段
include("database.php");
// Select one domain from the database that hasn't been checked yet
$sql = "SELECT domainName from domains WHERE 1 ORDER BY lastChecked ASC";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$domain = $row[0];
if(mysql_num_rows($result) == 0){
die("No domains found in the database.");
}
// Grab the WHOIS information for the domain selected
// ---------------------------------------------------------------
$domainExt = substr($domain, -3); // grab the domain extension
//var_dump($whois);
$arr = array($content);
foreach($arr as $id) {
echo $id, '<br>';
$data = file_get_contents('http://codestrike.net/domains/script.php?id='.$domain.'');
echo $data, '<br>';
}
foreach($data as $whoisline){
if(strstr($whoisline,"Expiration")){
$whoisline = str_replace("Expire Date:","",$whoisline);
$whoisline = trim($whoisline);
$expiration = substr($whoisline,0,11);
}
if(strstr($whoisline,"Status")){
$statusline = $whoisline;
}
}
$status = str_replace("Status:","",$statusline);
$status = trim($status);
Script.php?id=domain.com运行良好,这只是让whois.php从我的MySQL数据库中查找每个域的到期日期/状态的问题。
干杯。
更改:
$data = file_get_contents('http://mydomain.com/domains/script.php?id='.$domain.'');
至:
$data = file('http://mydomain.com/domains/script.php?id='.$domain);
file_get_contents
将整个文件作为单个字符串返回。file
将其拆分为一个数组,其中每个元素都是文件的一行。
您还需要在第一个foreach
循环中处理$data
。否则,在循环中每次都会覆盖$data
,而使用它的代码只会得到最后一个。
include("database.php");
// Select one domain from the database that hasn't been checked yet
$sql = "SELECT domainName from domains WHERE 1 ORDER BY lastChecked ASC";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$domain = $row[0];
if(mysql_num_rows($result) == 0){
die("No domains found in the database.");
}
// Grab the WHOIS information for the domain selected
// ---------------------------------------------------------------
$domainExt = substr($domain, -3); // grab the domain extension
//var_dump($whois);
$arr = array($content);
foreach($arr as $id) {
echo $id, '<br>';
$data = file('http://mydomain.com/domains/script.php?id='.$domain);
var_dump($data); echo '<br>';
foreach($data as $whoisline){
if(strstr($whoisline,"Expiration")){
$whoisline = str_replace("Expire Date:","",$whoisline);
$whoisline = trim($whoisline);
$expiration = substr($whoisline,0,11);
}
if(strstr($whoisline,"Status")){
$statusline = $whoisline;
}
}
$status = str_replace("Status:","",$statusline);
$status = trim($status);
}