Jump to content

Getting the domain name of a 301 redirected URL with masking enabled


BenRacicot

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.