我在互聯網上發現了一個從WHOIS服務器獲取數據並提取相關數據(例如到期日期,狀態)的現有腳本。由於它被遺棄了很長時間,我一直在修改它,並創建了我自己的script.php?id=domain.com
,它允許我輸入任何域名和whois數據, 我遇到麻煩的是我有我的whois.php文件,我想要列表的域出於我的MySQL數據庫,並試圖使用(file_get_contents到我的script.php和foreach)提取每個域的Expiry/Status數據,然後用相關信息更新數據庫。 我很確定我已經編碼了一切,除了「Foreach」&「File_get_contents」部分權限,因此我的腳本遇到錯誤。PHP file_get_contents foreach
「警告:()在/ home提供的foreach無效參數/ 用戶 /public_html/mydomain.com/domains/whois.php第39行上」
是我收到錯誤。
的片段我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($域,-3);'線真的很安全嗎?那麼foo.co.nz或bar.fr呢?你不應該使用正則表達式嗎? – Einenlum