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

Pixelbender

Senior Member
Joined
Jul 5, 2009
Messages
720
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
 

froot

Honorary Master
Joined
Jun 2, 2009
Messages
11,347
Just rough but it should work.

PHP:
$ref=@$HTTP_REFERER;
$to = "1@2.com";
$subject = "Referrer";
$message = 'The referring site is: '.$ref;
$headers = 'From: 1@2.com' . "\r\n" .
    'Reply-To: 1@2.com' . "\r\n";

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

Pixelbender

Senior Member
Joined
Jul 5, 2009
Messages
720
Hey Froot, how are you doing?

It sends the email - but the ref is blank

It just says this in the email: The referring site is:
 

froot

Honorary Master
Joined
Jun 2, 2009
Messages
11,347
PHP:
if(isset($_SERVER['HTTP_REFERER']))
{
$ref=$_SERVER['HTTP_REFERER']
$to = "1@2.com";
$subject = "Referrer";
$message = 'The referring site is: '.$ref;
$headers = 'From: 1@2.com' . "\r\n" .
    'Reply-To: 1@2.com' . "\r\n";

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

Broadcom

Well-Known Member
Joined
Aug 25, 2007
Messages
358
Deprecated. Try this:

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

Broadcom

Well-Known Member
Joined
Aug 25, 2007
Messages
358
Something like Froot said..

Code:
$ref = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : null;
if($ref) {
  $to = "1@2.com";
  $subject = "Referrer";
  $message = 'The referring site is: '.$ref;
  $headers = 'From: 1@2.com' . "\r\n" .
    'Reply-To: 1@2.com' . "\r\n";

  mail($to, $subject, $message, $headers);  
}
 

bin3

Senior Member
Joined
Jun 22, 2005
Messages
976
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 = "1@2.com";
$subject = "Referrer";
$message = 'The referring site is: '.$ref;
$headers = 'From: 1@2.com' . "\r\n" .
'Reply-To: 1@2.com' . "\r\n";

mail($to, $subject, $message, $headers);
}
 

Broadcom

Well-Known Member
Joined
Aug 25, 2007
Messages
358
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.
 

Pixelbender

Senior Member
Joined
Jul 5, 2009
Messages
720
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?
 

evilsee

Senior Member
Joined
Sep 12, 2003
Messages
563
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.
 

Broadcom

Well-Known Member
Joined
Aug 25, 2007
Messages
358
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);
}
 

Pixelbender

Senior Member
Joined
Jul 5, 2009
Messages
720
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.
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
@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
 

froot

Honorary Master
Joined
Jun 2, 2009
Messages
11,347
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
 

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
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...
 

Nod

Executive Member
Joined
Jul 22, 2005
Messages
9,861
The kids of today don't know how to google any more ...
 

froot

Honorary Master
Joined
Jun 2, 2009
Messages
11,347
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