This is a discussion on How can I access a case sensitive host name? within the PHP Language forums, part of the PHP Programming Forums category; Is there a way to echo back a case sensitive $HTTP_HOST in PHP? For example if I type HostName.domain....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Is there a way to echo back a case sensitive $HTTP_HOST in PHP? For
example if I type HostName.domain.com in my browser I want to return it exactly as it appears in the location part of the browser "HostName.domain.com" but it keeps returning a case insensitive result "hostname.domain.com". |
|
|||
|
Jeff wrote:
> Is there a way to echo back a case sensitive $HTTP_HOST in PHP? For > example if I type HostName.domain.com in my browser I want to return it > exactly as it appears in the location part of the browser > "HostName.domain.com" but it keeps returning a case insensitive result > "hostname.domain.com". I would imagine the hostname that's being passwed to $HTTP_HOST (and incidentally you should really be using $_SERVER['HTTP_HOST']) is what's defined in the web server's configuration, which is likely to be in lower case. It's possible that even if it were allowed to be in mixed case in the web server's config that it might still be passed to PHP as lowercase, or that the browser itself is lowercasing the domain when it makes the request to the server. Regardless of all this, there's no way you can assume that an end-user will actually type the domain into their browser using mixed case so you cannot rely on this in your script. At least now your other question about adding spaces before upper cased letters now has some context :) -- Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/ |
|
|||
|
In article <dXC9d.205753$MQ5.116054@attbi_s52>, Jeff wrote:
> Is there a way to echo back a case sensitive $HTTP_HOST in PHP? For > example if I type HostName.domain.com in my browser I want to return it > exactly as it appears in the location part of the browser > "HostName.domain.com" but it keeps returning a case insensitive result > "hostname.domain.com". Since when are hostnames case sensitive then? Are you even sure your browser requests Foo instead of foo? -- Met vriendelijke groeten, Tim Van Wassenhove <http://www.timvw.info> |
|
|||
|
On Fri, 08 Oct 2004 20:40:41 GMT, "Jeff" <jmox@mail.com> wrote:
>Is there a way to echo back a case sensitive $HTTP_HOST in PHP? For >example if I type HostName.domain.com in my browser I want to return it >exactly as it appears in the location part of the browser >"HostName.domain.com" but it keeps returning a case insensitive result >"hostname.domain.com". This behaviour makes sense - what's your need for case-sensitivity in the case-insensitive domain name system? RFC1035 sec 2.3.1 <http://www.ietf.org/rfc/rfc1035.txt> "Note that while upper and lower case letters are allowed in domain names, no significance is attached to the case. That is, two names with the same spelling but different case are to be treated as if identical." Monitoring HTTP requests with Ethereal made through Firefox and Internet Explorer 6 shows that it converts the host to lowercase before it makes the request - no mixed case Host: header gets through to the server. -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |
|
|||
|
Thanks guys, I now understand the potential problems with this approach.
I have decided using underscores to separate multiple words in the host name will prevent these problems while still enabling me to detect and decipher multi worded host names. |
|
|||
|
Jeff wrote:
> Thanks guys, I now understand the potential problems with this approach. > I have decided using underscores to separate multiple words in the host > name will prevent these problems while still enabling me to detect and > decipher multi worded host names. You'll be better to use dashes - and not underscores _ in your hostnames. I have seen underscores used in hostnames before, but you're only allowed a-z, 0-9 and - in domain names so it's best to stick to this for hostnames as well. -- Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/ |
|
|||
|
> For example if I type HostName.domain.com in my browser I want
> to return it exactly as it appears in the location part of the > browser [snip] I would venture to guess this isn't possible. What the user types in their address/location is a client request. His or her client takes this request and (via DNS) translates that to an address. If an appropriate program is listening at that address, it will process the request and send a response. I don't see anything on this path where the actual string typed by the user is ever going to be transmitted all the way to the web server and made available to server side programs. Since this string is client side, it might be possible to get to it through other client-side means (javascript, for example). --cd |
|
|||
|
> Thanks guys, I now understand the potential problems with this
approach. > I have decided using underscores to separate multiple words in the host > name will prevent these problems while still enabling me to detect and > decipher multi worded host names. You've got me curious: what are you doing? I don't mean that negatively: I'm really curious what you're up to here, if you don't mind sharing. --cd |
|
|||
|
>I would venture to guess this isn't possible. What the user types in
>their address/location is a client request. His or her client takes this >request and (via DNS) translates that to an address. If an appropriate >program is listening at that address, it will process the request and >send a response. Modern web servers that serve multiple web sites depend on the HTTP Host: header to determine what virtual host the request is for. The days of needing a separate IP address for each virtual host were long over 5 years ago. A typical setup will have DNS entries for www.mysite.com and www.yoursite.com and maybe a few hundred other names CNAMEd (or, it could use A records) to www.ispwebserver.com. Apache (or other server software) looks at the Host: header to figure out which site ("virtualhost") the request is for, and serves up the appropriate pages. You CANNOT tell this by the IP address (the same for all 3 names above). >I don't see anything on this path where the actual string typed by the >user is ever going to be transmitted all the way to the web server and >made available to server side programs. The host name as the user types it should appear in the Host: header. However, no guarantees that the case won't be changed before it gets to the server, and definitely no guarantees that the server won't just give the virtual host name as it appears in the config file. Gordon L. Burditt |