Forum Moderators: coopster

Message Too Old, No Replies

Handling external redirects using PHP

         

reshadat

4:34 am on Jun 5, 2009 (gmt 0)

10+ Year Member



How Can I detect if the page is requested internally using htaccess or externally using PHP. I want to achieve external redirection using PHP.With htaccess, we can do this by:
RewriteCond %{THE_REQUEST} ^GET\ /.*\;.*\ HTTP/

How Can I achieve the same thing using PHP?

penders

1:54 pm on Jun 5, 2009 (gmt 0)

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



You can check the value of $_SERVER['HTTP_REFERER']. If it contains your domain then it's requested internally, if it's empty then it's probably been requested directly (ie. URL typed in the address bar), otherwise it's an external request.

Bear in mind that $_SERVER['HTTP_REFERER'] may not be set all. Some browsers might not send a referer (or may be a browser plugin is preventing it from being sent). And it could be faked (browser plugin etc.), so it's not 100%. But then that's the same if you were using .htaccess.