By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,718 Members | 1,275 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,718 IT Pros & Developers. It's quick & easy.

How can I access a case sensitive host name?

P: n/a
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".
Jul 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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/
Jul 17 '05 #2

P: n/a
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>
Jul 17 '05 #3

P: n/a
On Fri, 08 Oct 2004 20:40:41 GMT, "Jeff" <jm**@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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #4

P: n/a
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.
Jul 17 '05 #5

P: n/a
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/
Jul 17 '05 #6

P: n/a
> 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
Jul 17 '05 #7

P: n/a
> 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
Jul 17 '05 #8

P: n/a
Sounds good, thanks.
Jul 17 '05 #9

P: n/a
>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
Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.