PHP: Get informed by e-mail when someone visits your site

The code below sends e-mail when someone visits your site (except yourself, assuming that you are testing locally):

if(!empty($_REQUEST)){
$theRemoteAddr = $_SERVER['REMOTE_ADDR'];
$theRemoteHost = gethostbyaddr($_SERVER['REMOTE_ADDR']);
//send mail:
$receiver="myself@mymail.com";
$from="info@swkb.net";
$subject="someone entered into swkb.net today (".date("d/m/y").")";
$body = "IP address: ".$theRemoteAddr." and Host Name: ".$theRemoteHost;

//my IP: 111.222.11.22
if($theRemoteAddr!="111.222.11.22" && $theRemoteAddr!="127.0.0.1"){
$send_mail = mail($receiver,$subject,$body,"from:$from");
if($theRemoteAddr!="" && $theRemoteAddr!=""){
$send_mail;
}
}
}

 

Leave a Reply