I need a script that will email the referring url to a certain email address

Pixelbender

Senior Member
Joined
Jul 5, 2009
Messages
729
Reaction score
4
Location
Gauteng, Chancliff
Hey guys

I need some help here. I need a php or javascript script that will email the referring url to a certain email address, can anyone help, please.

Thanks Anton
 
PHP:
if(isset($_SERVER['HTTP_REFERER']))
{
$ref=$_SERVER['HTTP_REFERER']
$to = "[email protected]";
$subject = "Referrer";
$message = 'The referring site is: '.$ref;
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n";

mail($to, $subject, $message, $headers);  
}
else
{
echo "There is no referring page.";
}
Try this then rather.
 
Deprecated. Try this:

Code:
$ref = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : null;
if($ref) {
  mail ...
}
 
Last edited:
Just to explain a bit ...

// Check if the referer is set in the HTTP headers -- This might not always be the case
// Can potentially not have a referer at all, or some settings in the webserver might prevent you seeing this
$ref = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : null;

// If we did find a referer, the $ref variable will be filled in with something, so build your mail message and send it
if($ref) {
$to = "[email protected]";
$subject = "Referrer";
$message = 'The referring site is: '.$ref;
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n";

mail($to, $subject, $message, $headers);
}
 
Another thought, if you start getting overwhelmed with emails on a busy site, you could always log to a file instead of emailing. Or use Google Analytics which will give you all the low down you need.
 
Its working now thanks... Im using google analytics, but it's not quite what I need - it's basically just a test run and I wont do this forever, I'm interested in this log file, can you help me out?
 
Its working now thanks... Im using google analytics, but it's not quite what I need - it's basically just a test run and I wont do this forever, I'm interested in this log file, can you help me out?

How about you try it yourself first? Its the only way to really learn something.
 
Well, I did kinda ask for it...

Here's something you could probably use.

Code:
if (isset($_SERVER['HTTP_REFERER'])) logger('referrer.log');

function logger($filename, $msg=null)
{ 
  //date & time
  $str[] = "[" . date("Y/m/d h:i:s", time()) . "]";
  //URL
  $str[] = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  //user browser.. 
  $str[] = $_SERVER['HTTP_USER_AGENT'];
  //user IP address
  $str[] = $_SERVER['REMOTE_ADDR'];
  //referring page
  $str[] = $_SERVER['HTTP_REFERER'];
  //if any extra msg passed to logger
  if($msg) $str[] = $msg;
  
  // open file
  $file = @fopen($filename, "a");
  // write string
  @fwrite($file, join("\t", $str) . "\n");
  // close file
  @fclose($file);
}
 
Okay cool thanks, Broadcom, Im going to see if I can make it work.

@evilsee: I do see your point and I'm a firm believer or diy and learn from it... But, I cant try it myself, Im not a programmer and either I ask the guys on MyBroadband to help or I ask Google to help, I dont really see the difference, Im going to have to get it from somewhere, and of course I will learn from this, it's not as if I wont remember what I did or how it was done.
 
@evilsee: I do see your point and I'm a firm believer or diy and learn from it... But, I cant try it myself, Im not a programmer and either I ask the guys on MyBroadband to help or I ask Google to help, I dont really see the difference, Im going to have to get it from somewhere, and of course I will learn from this, it's not as if I wont remember what I did or how it was done.

How about hiring a ****ing freelancer to do it for you? It would AT MOST cost you $20
 
How about hiring a ****ing freelancer to do it for you? It would AT MOST cost you $20

Or just ask someone on here to do it and pay them.... would have taken a one hour slot on the invoice and charged at the applicable rate :P
 
Or just ask someone on here to do it and pay them.... would have taken a one hour slot on the invoice and charged at the applicable rate :P

I don't mind helping people out with existing code hey... most of the time a fresh set of eyes can pick up a comma or semi-colon that's needed that is screwing you around. But blatantly coming online ASKING (and getting?!) for code...for free... well it speaks VOLUMES as to how important everyone's time here is and how cheap this dude is.

EVEN AFTER SOMEONE GAVE HIM PSEUDO CODE WHICH HE COULD HAVE MODIFIED SIMPLY... it went on to several rewrites?!

Seriously: **** me up the ass because this industry took a turn for the worst somewhere...
 
The kids of today don't know how to google any more ...
 
I don't mind helping people out with existing code hey... most of the time a fresh set of eyes can pick up a comma or semi-colon that's needed that is screwing you around. But blatantly coming online ASKING (and getting?!) for code...for free... well it speaks VOLUMES as to how important everyone's time here is and how cheap this dude is.

EVEN AFTER SOMEONE GAVE HIM PSEUDO CODE WHICH HE COULD HAVE MODIFIED SIMPLY... it went on to several rewrites?!

Seriously: **** me up the ass because this industry took a turn for the worst somewhere...

/me nods
 
Top
Sign up to the MyBroadband newsletter
X