Jump to content

Recommended Posts

Sorry for the spam today, ive been on the computer all day trying things out due to the weather, so I have nothing better to do

 

anyway, I saw this code on this site , its a script that emails you when somebody is referred to your site via google

 

heres the code

 

<?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'];

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

   parse_str($referrer, $output);
   $keywords=$output['q'];
   
   $email_message="Hi $name, A visitor just arrived to your site after searching for '$keywords'. ($referrer)";

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

}
?>

 

I filled out all the necessary variables, but cant get it to work. Is there something missing? I tried making it a seperate file, and used function.include() to include it, that didnt work. I tried html object tags, that didnt work, then I just put that code in the page. Nothing working.

 

What could it be?

 

Thank you all for your support, thanks to you all, I am making php applications that I thought I never could!

http://us.php.net/manual/en/reserved.variables.server.php

'HTTP_REFERER'

    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

 

the script starts out: "If the referrer contains google and search", mail this message.  Running it from your own server will not work unless you modify your UA to pretend to be a google page.

http://us.php.net/manual/en/reserved.variables.server.php

'HTTP_REFERER'

    The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

 

the script starts out: "If the referrer contains google and search", mail this message.  Running it from your own server will not work unless you modify your UA to pretend to be a google page.

 

Thanks, do you know how to modify the user agent?

Not personally, I'm sure you could google it.  Likewise, you could test the script yourself by setting a variable to pretend to be from google at the top.

 

I don't know off the top of my head, but just check out what the necessary HTTP_REFERER string looks like for the script, and set it at the top of your page to test.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.