Jump to content

Receive and email when google refers a visitor part 2.


chrismarsden

Recommended Posts

Hi, didnt know how to add this to the repository so can an admin move this please.

 

this updated version will tell you still when you recieve a visitor but to identify who i have included so that it tracks the ip and tells you when its you!!!

 

<?php
// Script to email you when Google refers traffic to your site.
$name=""; // add your name here
$email_address=""; // add your email address here

$keywords="";
$referrer=$_SERVER['HTTP_REFERER'];

$known_ips = array(
    '01.01.01.01' => 'from the computer your are at now!',
    // etc.
);

$ip = $_SERVER['REMOTE_ADDR'];

if (array_key_exists($ip, $known_ips))
{
    $ip = $known_ips[$ip];
    // you may want to use a different var name here now?
}



if( (stristr($referrer, "google")) && (stristr($referrer, "search")) ) {

   parse_str($referrer, $output);
   $keywords=$output['q'];

   $email_message="A visitor just arrived to the website after searching for '$keywords', Their IP address is '$ip'. ($referrer)";

   mail ("$email_address","Google referred a visitor","$email_message");
  
}
?>

 

 

hope it all works... give it a try and let me know.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.