Jump to content

Referring URL


JonEMD

Recommended Posts

Hello everyone,

 

I'm having real trouble with something I'm sure most of you would find easy....

 

...here we go.....

 

...I want a redirect script based on referring URL. More specifically, a small part of the referring URL.

 

example....

 

ad is placed on Bing, if someone clicks on the ad they get directed to a URL starting "0.r.msn.com/?Id=54r645f3345e" which redirects to my site. I want the referrer checker to looks specifically for the ".r.msn.com/?Id=" and if it's present let the visitor through to the site. The reason I only want it to check for that small part of the URL is because the bits before and after are variables and that is the only "static" part.

 

However, if someone arrives at my site by not clicking on an ad, I want them to go somewhere completely different, let just say for arguments sake,  google.com.

 

This is what I have so far...

 

 

<?php

$_GET = $_SERVER['HTTP_REFERER'];

if ($_GET == '.r.msn.com')

{

header('Location: http://www.mysite.com');

}

else

{

header('Location: http://www.google.com');

}

?>

 

 

 

I must be missing something, please help.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/232068-referring-url/
Share on other sites

First of all you're trying to overwrite the super-global $_GET array with the HTTP referrer. Just use strpos() to check if the match is found within the HTTP referrer:

 

<?php
if (strpos($_SERVER['HTTP_REFERER'], '.r.msn.com') !== false)
{
header('Location: http://www.mysite.com');
}
else
{
header('Location: http://www.google.com');
}
?>

Link to comment
https://forums.phpfreaks.com/topic/232068-referring-url/#findComment-1193732
Share on other sites

MrAdam,

 

Thanks for the reply. I'm still having some difficulty though :(.

 

I changed the referrer in the code you pasted so I could test it on one of my domains and it seemed to work. However, when I went straight to the file with the code in it directed me as if the referrer was in place. (the domain I set up the redirect from was privateclicktracking.com so I replaced '.r.msn.com' with 'ktracking.com' (just to test if it would pick up part of the URL)

 

Does it have anything to do with the !== false) part?

 

Sorry if I sound like a complete idiot

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/232068-referring-url/#findComment-1193786
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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