Connecting Tech Pros Worldwide Help | Site Map

How to detect local host?

Daniel Loose
Guest
 
Posts: n/a
#1: Jul 17 '05
Hello,

in order to use my scripts developed at home directly after upload, I
wish to define a variable $root at begin of each script in a way that
it always - be it here at home or on any other computer - contains the
correct path to the web docs directory. How shall I do that the best
way? (At least, how do I get the local IP or hostname? Or is there an
environment variable?) Grepped 4 thick books but nothing found...

TIA, Daniel
Ewoud Dronkert
Guest
 
Posts: n/a
#2: Jul 17 '05

re: How to detect local host?


On Sun, 05 Jun 2005 16:51:56 GMT, Daniel Loose wrote:[color=blue]
> correct path to the web docs directory.[/color]

$_SERVER['DOCUMENT_ROOT'] but maybe that's Apache specific, dunno.


--
Firefox Web Browser - Rediscover the web - http://getffox.com/
Thunderbird E-mail and Newsgroups - http://gettbird.com/
Chuck Anderson
Guest
 
Posts: n/a
#3: Jul 17 '05

re: How to detect local host?


Daniel Loose wrote:
[color=blue]
>Hello,
>
>in order to use my scripts developed at home directly after upload, I
>wish to define a variable $root at begin of each script in a way that
>it always - be it here at home or on any other computer - contains the
>correct path to the web docs directory. How shall I do that the best
>way? (At least, how do I get the local IP or hostname? Or is there an
>environment variable?) Grepped 4 thick books but nothing found...
>
>TIA, Daniel
>
>[/color]
If I understand you right, .... what I do is look at the SERVER variable
HTTP_HOST.

if ($_SERVER['HTTP_HOST'] == 'localhost')
{
// the script is running on my home computer and not on the remote server
}
else
{
// $_SERVER['HTTP_HOST'] contains the domain name where my script is running
}

--
*****************************
Chuck Anderson • Boulder, CO
http://www.CycleTourist.com
Integrity is obvious.
The lack of it is common.
*****************************
Tony Marston
Guest
 
Posts: n/a
#4: Jul 17 '05

re: How to detect local host?


$_SERVER['SERVER_NAME'] will return the name of the server. This will be
either 'LOCALHOST' or something different.

You should not need this anyway as $_SERVER['DOCUMENT_ROOT'] will contain
the right information. This works for me as I develop on Windows and upload
the same scripts to a Linux box.

--
Tony Marston

http://www.tonymarston.net



"Daniel Loose" <noreply@web.de> wrote in message
news:42a32bb1.14911159@news.cs.tu-berlin.de...[color=blue]
> Hello,
>
> in order to use my scripts developed at home directly after upload, I
> wish to define a variable $root at begin of each script in a way that
> it always - be it here at home or on any other computer - contains the
> correct path to the web docs directory. How shall I do that the best
> way? (At least, how do I get the local IP or hostname? Or is there an
> environment variable?) Grepped 4 thick books but nothing found...
>
> TIA, Daniel[/color]


chotiwallah
Guest
 
Posts: n/a
#5: Jul 17 '05

re: How to detect local host?


i use a config file for these cases, because usually not only pathes
differ between your dev box at home and the actually server (database
pswd do often, for instance).
i require that file at the top of each script and keep two different
config files.

micha

steve
Guest
 
Posts: n/a
#6: Jul 17 '05

re: How to detect local host?


"Daniel Loose" wrote:[color=blue]
> Hello,
>
> in order to use my scripts developed at home directly after
> upload, I
> wish to define a variable $root at begin of each script in a
> way that
> it always - be it here at home or on any other computer -
> contains the
> correct path to the web docs directory. How shall I do that
> the best
> way? (At least, how do I get the local IP or hostname? Or is
> there an
> environment variable?) Grepped 4 thick books but nothing
> found...
>
> TIA, Daniel[/color]

I use php in web and batch mode, and some of the $_SERVER variables
don’t work in batch mode. I use getcwd
http://ca3.php.net/manual/en/function.getcwd.php to look at the path,
and from that detect where the app is running.

--
Posted using the http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/PHP-detect-l...ict229718.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=796276
Closed Thread