Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

Detect and distinguish between local and external referers


Recommended Posts

I've got several popup_image.php URLs indexed in search engines, which is good.


But unfortunately, popup_image.php contains javascript that resizes the browser window to the proportions of the image, which is not a friendly behavior for a new visitor arriving from a search engine.


I'd like to figure out how to detect whether the request for popup_image.php came from a cart page (in which case the default popup_image.php is fine) or if the request came from an external site such as a search engine (in which case I'd like to have the javascript removed).


I've been experimenting a lot and I don't have any problem using if / else statements to control whether the javascript is echoed to the page, but where I'm having trouble is with the method for detecting and distinguishing the referrer.


Any help would be extremely welcomed.



Link to comment
Share on other sites

Something like this in your code:



That will set the var $ref to the complete URL of the referring page, like:



If I suggest you edit any file(s) make a backup first - I'm not perfect and neither are you.


"Given enough impetus a parallelogramatically shaped projectile can egress a circular orifice."

- Me -


"Headers already sent" - The definitive help


"Cannot redeclare ..." - How to find/fix it


SSL Implementation Help


Like this post? "Like" it again over there >

Link to comment
Share on other sites

Hi Jim,


Thanks for that. At first I was disappointed because I'd already tried HTTP_REFERER, but I realized that I hadn't tried it using $_SERVER[HTTP_REFERER]


Once I did and I started getting positive results, it didn't take much longer to piece it together. So, in case anyone else is interested in the solution, here's what I'm using to detect and distinquish:

$host = str_replace("www.","",$_SERVER['SERVER_NAME']);
if (!strpos($ref, $host)) {echo 'page without javascript for visitor coming from SE'; } else {echo 'page with javascript for visitor already in cart';}

Obviously there's no need to put the entire page into the echo commands, that's just for illustration.


So, thanks again Jim.



Link to comment
Share on other sites


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

  • Create New...