FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Get the Domain name of the Referrer





ninjakannon
I know that using $_SERVER['HTTP_REFERER'] would return the whole page URL that referred the user to the current page. However it is not very reliable as it can be changed and not all browsers set this.

But is there any other way to retrieve the same result? All I really want is the domain name, but the whole URL would be fine.
alalex
what i used in my site was this:
Code:
function get_from(){
   $visit = $_SERVER['HTTP_REFERER'];
   if($visit == '' || $visit == ' '){
      $visit = '[organic]';
   }else{
      $parts = explode('/',$visit);
   }
   $site = $parts[2];
   $text = 'You are coming from: ';
   echo $text.$site;
}


it works great for me!
ninjakannon
I know about "$_SERVER['HTTP_REFERER']" and can use it; I just don't wish to. I'm looking for a method that has 100% certainty of working. In my experience less than 50% of browsers set the HTTP_REFERER and users can change it manually, anyway - it's pretty unreliable.

Also, would your script not be better like this?:

Code:
function get_from(){
   if(isset($_SERVER['HTTP_REFERER'])){
      $visit = $_SERVER['HTTP_REFERER'];
      $parts = explode('/', $visit);
   }else{
      $visit = '[organic]';
   }
   echo "You are coming from: $parts[2]";
}


It's more compact that way, but does the same thing.

To be honest I don't think it's possible to do what I want using this method, unless the referring page uses either of these:

Code:
$_SERVER['SERVER_NAME'];
$_SERVER['HTTP_HOST'];


But anyway this would be pretty useless as it would only work internally to your website, and then you would know the referrer anyway.

I've found a solution to what I initially needed this information for - I just thought a little about it and in the end it was extremely simple. This query here is more out of interest than anything now; I just don't think it's possible.

Thanks for your suggestion all the same, alalex.
alalex
o, i see now what you mean, why dont you just use javascript with history.back(-1) to get the last visited page, or you do that with php, and then you can get the servername with the explode?

is just my little contribution.. Wink
ninjakannon
I've achieved what I wanted to do using a session variable, I don't know why I didn't want to do that before. Razz

Thanks though. Smile
Related topics
Ok a little help for a semi-beginner
Can I use a .com.ru domain name when requesting free hosing?
Free domain names
Hosting my own domain name on Frihost
domain name help
JJstorm has registered (and wants his own domain name)
'Where To' For Domain Name Registration?
Does anyone know where I could get a FREE domain name?
change domain name
What i need make, to authorize domain name in yours DNS?
Want to host a Domain name
domain name not working
Question about Domain name and add-on domain
Keep domain name in URL space
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.