2017-05-17 40 views
-2

我正在嘗試創建一個PHP,可以從請求中記錄HTTP信息,然後通過電子郵件發送此信息。我試圖發送IP,URL引用和URL請求)如何登錄「請求信息」然後通過電子郵件發送?

的想法是,$emailContent可以發送:

"Someone visited your webpage. IP address:".$remoteIpAddress; 
"The referrer URL from the request was:".$urlRefer 
"The URL input was: php?".$infoFromUrl 

$ infoFromUrl意味着發送類似log.php URL信息發送,這 - 信息,通過郵件

誰能幫助我:

<?php 

$yourEmailAddress = "[email protected]domain.com"; 
$emailSubject = "New Visitor on Webpage"; 
$remoteIpAddress = $_SERVER['REMOTE_ADDR']; 
$emailContent = "Someone visited your webpage. IP address:".$remoteIpAddress; 

// send the message 
mail($yourEmailAddress, $emailSubject, $emailContent); 

?> 
+0

你的問題還不清楚,你究竟在努力達到什麼目的。你想發送日誌數據作爲電子郵件? – Kuru

+0

是的。我想在PHP文件調用時自動發送信息。我正在調查'HTTP_REFERER' – pancho

+0

你有一些代碼。沒有什麼是明顯的錯誤。有什麼問題? – Quentin

回答

-1

你有電子郵件的代碼是非常基本的,但應該工作 - 考慮PHPMailer,如果你想要做一個MOR徹底的工作。

日誌可以很簡單:

$msg = "Someone visited your webpage. IP address:" . $remoteIpAddress. 
    "The referrer URL from the request was:" . $urlRefer . 
    "The URL input was: php?" . $infoFromUrl; 
file_put_contents('log.txt', date('Y-m-d H:i:s ').$msg, FILE_APPEND | LOCK_EX); 

或者你可以通過使用實施the PSR-3 standard類更復雜。

相關問題