Re: How to get the Web Address of the Script

From: Date: Sun, 21 Sep 2003 05:41:37 +0000
Subject: Re: How to get the Web Address of the Script
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-163331@lists.php.net to get a copy of this message
* Thus wrote Dan Anderson (dan@mathjunkies.com): > I am creating a script and there is an autoconfig file. I want to read > in the web address of the server, and throw some correct URLs into the > database. > > Will using $_SERVER['HTTP_HOST'] guarantee getting me the domain name of > the server on which the web page I am viewing is hosted? > > I am somewhat worried about using such variables because I seem to > remember it being possible to disable them in PHP.ini, but I would love > to get some feedback. It rather depends on the webserver but in most cases it will be there. On apache the way it works is when you access the url http://yourhost.com/ The most browsers will send something like: GET / HTTP/1.1 host: yourhost.com The host: header is what HTTP_HOST is. If you can access the site by the IP, I'm not exactly sure what will happen in that case, cause the browser may not send that host: value. With all that said, if you have the HTTP_HOST value, it will most likely be there. php has no control over that var, its set by the webserver. HTH Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#163331) next »