森林之原
五月 23, 2012, 03:08:22 pm *
歡迎光臨, 訪客. 請先 登入註冊一個帳號.

請輸入帳號, 密碼以及預計登入時間
新聞: 森林之原歡迎您的蒞臨!
森林之原提供自由軟體的支援,包括繁體中文的翻譯。
 
   首頁   說明 搜尋 日曆 登入 註冊  
頁: [1]   向下
  寄送主題  |  列印  
作者 主題: 檢查郵件伺服主機的真偽  (閱讀 2557 次)
0 會員 以及 2 訪客 正在閱讀本篇主題.
禁海蒼狼
初學者
*
離線 離線

文章: 41


« 於: 一月 22, 2007, 09:48:26 am »

檢查郵件伺服主機的真偽:

-----------------------------------------------------------------------------------------
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





向版主檢舉   已記錄
頁: [1]   向上
  寄送主題  |  列印  
 
前往:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006, Simple Machines LLC Valid XHTML 1.0! Valid CSS!