Skip to main content
Inspiring
January 29, 2010
Question

Show referring site using PHP

  • January 29, 2010
  • 2 replies
  • 1225 views

Hi

I am obviously using PHP

Is there a way to check the referring site on a page. I know about the getenv("HTTP_REFERER") but that gets the entire URL. I only want the main url.

For example:

when I use getenv("HTTP_REFERER") when someone comes from http://www.google.com/search?hl=en&source=hp&q=pie&aq=f&aqi=&oq= it displays that whole url.

I only want it to display the http://www.google.com or just google.com.

Any and all help is always appreciated.

This topic has been closed for replies.

2 replies

David_Powers
Inspiring
January 30, 2010

Use parse_url().

if ($url = getenv('HTTP_REFERER'){

  echo $url['host'];

}


Participating Frequently
January 30, 2010

That's cheating


David_Powers wrote:

Use parse_url().

if ($url = getenv('HTTP_REFERER'){
  echo $url['host'];
}


cwhazzooAuthor
Inspiring
January 30, 2010

Thank you both. I was having a very difficult time researching this. Thank you again.

Participating Frequently
January 29, 2010

Get familiar with the string functions of your scripting language. You can easily locate the position of the third forward slash and use a left() function to get the part you need.