Check referrer for certain url
I have some device redirection PHP at the top of each of my sites pages that I want to disable if the page was reached from a certain url.
How can I disable this PHP if the user arrived at that page by clicking from http://www.mysite.com/mobile
That url could change, ie: http://www.mysite.com/mobile/blah/blah or http://mysite.com/mobile/blah/
I just nee开发者_开发问答d to check for the 'mysite.com/mobile' part.
You can use either:
$_SERVER['REQUEST_URI'] and $_SERVER['REQUEST_URL']
Basically you would want to check where you are at:
if($_SERVER["REQUEST_URI"]!="/mobile/index.php"){
header("location: ");
exit;
}
You need to grab the referrer from the header. e.g. Check if @$HTTP_REFERER is equal to 'http://www.mysite.com/mobile' and then code accordingly.
If the referring URL is going to change, then you may need to splice the referrer out to look for the host, and certain path's such as '/mobile'. If it's not, and you have a constant list of possible referring URLs, then you'll simply need to loop through the URLs and check them against the @$HTTP_REFERER variable.
<?php
echo $HTTP_REFERER;
?>
The page referrer is found by using the $HTTP_REFERER variable. This is a quick way of looking up where people are navigating to your pages from. Once you know this information you can also filter users based upon it. For example, you only let people who come from one of your referring pages to use your downloads section, etc. Unfortunately $HTTP_REFERER is not foolproof. Some browsers do not send this information, or can be made to send false information. You should keep this in mind when working with $HTTP_REFERER.
精彩评论