|
|
Subject:
User Redirect Based on Referring URL
Category: Computers > Programming Asked by: thatonedude-ga List Price: $2.50 |
Posted:
20 Aug 2005 13:25 PDT
Expires: 19 Sep 2005 13:25 PDT Question ID: 558128 |
I need a script (PHP) that would block a user from viewing it unless they came from a specific URL and no other. (e.g., a user coming from www.worldpay.com would be able to view it but a user coming from google.com or anywhere else would not - and would be redirected to a different page on my site.) |
|
Subject:
Re: User Redirect Based on Referring URL
Answered By: palitoy-ga on 20 Aug 2005 23:56 PDT |
Hello thatonedude-ga Thank-you for your question. In PHP you can determine where the user came from by the following line of code: <? $referer = $_SERVER['HTTP_REFERER']; ?> If you wish only the domain name they came from rather than the full URL then you can use this: <? $referer = parse_url(htmlspecialchars(strip_tags($_SERVER['HTTP_REFERER']))); ?> To redirect a user away from a page if they did not come from the correct location you would place the following code at the start of the page you did not wish them to see. This must be placed before *any* other code on the page. <? // get the page the user came from and store it in the variable $referer $referer = parse_url(htmlspecialchars(strip_tags($_SERVER['HTTP_REFERER']))); // if the variable $referer is not EXACTLY // equal to http://www.worldpay.com then // redirect them to http://foobar.com if ( $referer != "http://www.worldpay.com" ) { header('Location: http://foobar.com/'); exit; }; ?> This is the basics that you require for this procedure. You will need to edit the above code to exactly fit your needs (that is where the not wanted user is redirected to and what the $referer must match). If you require any further information on this question please ask for clarification and I will do my best to help. | |
| |
|
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |