【发布时间】:2014-04-17 06:17:59
【问题描述】:
我在 Internet 上找到了一个现有脚本,该脚本从 WHOIS 服务器获取数据并提取相关数据(例如到期日期、状态)。由于它被遗弃了很久,我一直在修改它并创建了我自己的script.php?id=domain.com,它可以让我输入任何域并显示 whois 数据,
我遇到的问题是我有我的 whois.php 文件,我想从我的 MySQL 数据库中获取域列表并尝试使用 (file_get_contents 到我的 script.php 和foreach) 然后使用相关信息更新数据库。
我相当肯定我已经编写了除“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是一个字符串,您不能将其作为foreach的参数传递 -
你想循环通过数据库记录而不是通过接收到的文件内容你在这里所做的是循环通过文件获取内容而不是通过数据库中的记录..
-
Offtopic 但是……你的
$domainExt = substr($domain, -3);线路真的安全吗?那么 foo.co.nz 或 bar.fr 呢?你不应该使用正则表达式吗?
标签: php mysql foreach file-get-contents whois