BenRacicot Posted January 27, 2014 Share Posted January 27, 2014 Hello, I'm trying to grab the domain from a 301 redirect with masking. I can grab the domain name in Chrome with: <?php echo parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); ?> This doesn't work in other browser because: from the php manual, "This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. Anyone have experience reliably getting the 'domain.com' from the referrer when dealing with 301 redirect (with masking) in all browsers? (if it must be done with regex can you please be detailed) Thanks Quote Link to comment https://forums.phpfreaks.com/topic/285719-getting-the-domain-name-of-a-301-redirected-url-with-masking-enabled/ Share on other sites More sharing options...
.josh Posted January 27, 2014 Share Posted January 27, 2014 parse_url just parses the (url) string you give it. There are no php functions or methods to get the referring URL if it's a masked 301 redirect, or otherwise get it if the user agent simply doesn't provide it or lie about it. For example, say you are in your browser and have an addon like tamper data. When the request is made, you can set Tamper Data to strip whatever headers, or alter the values. So the overall message here is that you can't rely on that data as 100%. You have to treat it like you do any other user input, like from a form. Bottom line is there is no reliable method of getting the true value. What you already have is as reliable as it can get. There's nothing you can do with regex (or other means) that parse_url can't already do*, because the problem is getting an accurate string to work with in the first place. *actually parse_url doesn't account for several edge-case url formats, so if you're looking for a more thorough version of it, ctrl+f the user comments in the manual entry for "j_parse_url". But the previous statements still stand: the core issue is not a limitation of parse_url, but in the server itself reliably receiving a value that isn't tampered with or omitted. Quote Link to comment https://forums.phpfreaks.com/topic/285719-getting-the-domain-name-of-a-301-redirected-url-with-masking-enabled/#findComment-1466752 Share on other sites More sharing options...
BenRacicot Posted January 27, 2014 Author Share Posted January 27, 2014 Excellent answer, thank you. Can you point me in the right direction for how to reliably get the 301 redirected URL? get['url'] or By using JS instead? Quote Link to comment https://forums.phpfreaks.com/topic/285719-getting-the-domain-name-of-a-301-redirected-url-with-masking-enabled/#findComment-1466757 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.