檢查郵件伺服主機的真偽:
-----------------------------------------------------------------------------------------
checkdnsrr --- 檢查DNS記錄
checkdnsrr
(PHP3 , PHP4)
checkdnsrr --- 檢查DNS記錄
語法 : int checkdnsrr (string host [, string type])
說明 :
搜尋DNS型態type的記錄,如果找到記錄則傳回true,如果找不到記錄或是發生錯誤則傳回false。
type可以是A、MX、NS、SOA、PTR、CNAME或是ANY的任何一個,預設是MX。
host可以是IP位址或是主機名稱。
-----------------------------------------------------------------------------------------
原本可以利用這個指令來驗證郵件伺服主機的真偽,可是在 Windows 環境下使用不但無效,還會造成
WEB 伺服器中斷。因此在網路上找了好久,終於找到了高人撰寫的替代程式。
本段程式可以應用在使用PHP來撰寫的各種論壇、部落格、相簿等程式。
現在將應用在CPG上的方式分享給大家。
測試用CPG版本:1.42
本次共修改2個檔案:
/register.php
/profile.php
修改:/register.php (註冊程序)
找到:
$profile6 = addslashes($_POST['user_profile6']);
在下面加入:
//檢查郵件伺服主機的真偽--還要修改 profile.php
function myCheckDNSRR($hostName, $recType = '')
{
if(!empty($hostName)) {
if( $recType == '' ) $recType = "MX";
exec("nslookup -type=$recType $hostName", $result);
// check each line to find the one that starts with the host
// name. If it exists then the function succeeded.
foreach ($result as $line) {
if(eregi("^$hostName",$line)) {
return true;
};
};
// otherwise there was no mail handler for the domain
return false;
};
return false;
};
if (!myCheckDNSRR(substr(strstr($email,'@'),1),"")){
$error = '<li>'. '抱歉, 您所使用的 '. substr(stristr ($email,'@'),1) .' 郵件伺服主機是錯誤的。';
return false;
}
//檢查郵件伺服主機的真偽--還要修改 profile.php
修改:/profile.php (會員個人資料程序)
找到:
$email = addslashes($_POST['email']);
在下面加入:
//檢查郵件伺服主機的真偽--還要修改 register.php
function myCheckDNSRR($hostName, $recType = '')
{
if(!empty($hostName)) {
if( $recType == '' ) $recType = "MX";
exec("nslookup -type=$recType $hostName", $result);
// check each line to find the one that starts with the host
// name. If it exists then the function succeeded.
foreach ($result as $line) {
if(eregi("^$hostName",$line)) {
return true;
};
};
// otherwise there was no mail handler for the domain
return false;
};
return false;
};
if (!myCheckDNSRR(substr(strstr($email,'@'),1),"")){
cpg_die(ERROR, '抱歉, 您所使用的 '. substr(stristr ($email,'@'),1) .' 郵件伺服主機是錯誤的。', __FILE__, __LINE__);
return false;
}
//檢查郵件伺服主機的真偽--還要修改 register.php