This is the web log of Tim Bennett, web designer. He also runs Texelate, offering the best web design Leeds, Yorkshire has to offer

Real time alerts when people visit your site with PHP

Wednesday, April 1st, 2009 at 1:23 pm

I thought I’d post this code I use on some of my sites. Basically when someone finds your site from another site it emails you and tells you where they came from. I know stats software is much more powerful but this is quite nice as it’s in real time.

if( !empty( $_SERVER[ "HTTP_REFERER" ] ) && substr_count( $_SERVER[ "HTTP_REFERER" ], “www.yourdomain” ) == 0 ) {

    $subject = “Someone has found YOUR WEBSITE NAME HERE”;

    $m = $_SERVER[ "HTTP_REFERER" ] . “\n” . $_SERVER[ "REQUEST_URI" ] . “\n”;

    $m .= “\n\nMessage sent on ” . date( “H:i:s, d/m/Y” );

    $headers = “From: Your website name <contact@yourdomain.com> Reply-To: Your website name <contact@yourdomain.com>n”;

    $to = “youremail@yourdomain.com”;

    mail( $to, $subject, $m, $headers );

}

Although I’ve spent a lot of time reading the mails during the working day it gives you a good idea of how and when people find your site.

2 Responses to “Real time alerts when people visit your site with PHP”

  1. nadavvin says:

    thanks,
    Although then I add it to my blog it break it since some use of “ which php doesn’t like.

    P.S
    Since it doesn’t tell you what is the previous to the referer I got here since you list in the sponsor of Durian.

  2. nadavvin says:

    What is the purpose of the registration if the users cannot edit their posts?

Leave a Reply

You must be logged in to post a comment. If you don't have an account register one now.

Do you need a website or web-related service?
I run an award-winning web design studio.