Forum Moderators: coopster

Message Too Old, No Replies

referer URL function

simple function - am i missing something?

         

marcus76

3:42 pm on Dec 12, 2008 (gmt 0)

10+ Year Member



Hi,

I have the function as follows - i can't get it to return any results. Could someone please advise what it is i'm missing with this.

Thanks

Marcus

function getReferalHost()
{
$refer = parse_url($HTTP_SERVER_VARS['HTTP_REFERER']);
$host = $refer['host'];

if(strstr($host,'google'))
{
return 'Google';
}
elseif(strstr($host,'yahoo'))
{
return 'Yahoo';
}
elseif(strstr($host,'msn'))
{
return 'MSN';

}
}

dreamcatcher

12:21 am on Dec 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Marcus,

$HTTP_SERVER_VARS is deprecated and shouldn`t be used. Try the supergobal $_SERVER. Also, does the referer actually exist? Does the parse url array appear as expected?

print_r($refer);

dc

rainborick

4:27 am on Dec 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I noticed that your getReferalHost() function doesn't have a default value when the referer isn't one of the three search engines you're looking for. In other words, the function will return null if it isn't one of those search engines. And keep in mind that some security/privacy software for browsers and networks will set the Referer to an empty string, so you'll always have some users you'll never be able to detect.

Mahabub

11:51 am on Dec 14, 2008 (gmt 0)

10+ Year Member



dear marcus76,
Try the below one...

function getReferalHost(){
$refer = parse_url($HTTP_SERVER_VARS['HTTP_REFERER']);
$host = $refer['host'];
if($host=='')
return 'No refer';

if(strstr($host,'google'))
{
return 'Google';
}
elseif(strstr($host,'yahoo'))
{
return 'Yahoo';
}
elseif(strstr($host,'msn'))
{
return 'MSN';
}
else{

return 'Unknown';
}
}

Thanks
Mahabub

Habtom

12:38 pm on Dec 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



referers are not very reliable, the value depending on browsers might not be there at times.