[thelist] Links and Spiders (PHP solution)
Timothy J. Luoma
luomat at operamail.com
Sun Dec 29 12:34:00 CST 2002
This is what I use to get an email whenever there is a non-blank referrer
that is not from my own domain.
Make sure you change the MAIL_TO and MAIL_FROM to suit your setup.
<?php
// this should give you the URL of the previous page if it was a link
$PREVIOUS_URL = $_SERVER['HTTP_REFERER'];
// this should return your domain name without the "www."
$DOMAIN = $_SERVER['SERVER_NAME'];
if ("$PREVIOUS_URL" != "" ) {
if(!strstr($PREVIOUS_URL,$DOMAIN)) {
// we don't set these variables unless we get here
// because it would be wasteful to set variables before
// we know we will use them
// this is the local page that was linked TO
$LOCAL_PAGE = $_SERVER["REQUEST_URI"];
// this gives you the remote IP, useful for checking where they // went
from their initial page
$REMOTE_HOST = $_SERVER["REMOTE_ADDR"];
// this tells you what browser they are using
$UA = $_SERVER["HTTP_USER_AGENT"];
// I want to ignore referrer logs from this particular UA
if ("psbot/0.1 (+http://www.picsearch.com/bot.html)" == "$UA" )
{
exit () ;
}
// set this to be the email address where these messages are sent TO
$MAIL_TO = "lists@$DOMAIN";
// set this to be the email address where these messages are reported as
being FROM
$MAIL_FROM = "Link Reporter <tracker@$DOMAIN>" ;
// This will be the Subject line of the message
$SUBJECT = "$DOMAIN Link: $LOCAL_PAGE -- $PREVIOUS_URL" ;
// Don't change this unless you know what you are doing
$HEADERS = "From: $MAIL_FROM\n" ;
// This collects the information that we have assembled and puts it into a
message body
$MESSAGE = "
Host: $REMOTE_HOST
From: <$PREVIOUS_URL>
To: http://$DOMAIN$LOCAL_PAGE
UA: $UA
";
// this actually sends the message
mail("$MAIL_TO", "$SUBJECT", "$MESSAGE", "$HEADERS");
// this is for debugging. It will put the information above into the body
of the web page.
// Remove this or comment it out when you know it works
// echo <<< EOD
// <!-- // mailto $MAIL_TO
// subject $SUBJECT
// message $MESSAGE
// headers $HEADERS
// -->
EOD;
// here is the end of the debugging thing
}
}
?>
More information about the thelist
mailing list