467,087 Members | 1,234 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,087 developers. It's quick & easy.

How to detect local host?

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
Jul 17 '05 #1
  • viewed: 4595
Share:
5 Replies
On Sun, 05 Jun 2005 16:51:56 GMT, Daniel Loose wrote:
correct path to the web docs directory.


$_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/
Jul 17 '05 #2
Daniel Loose wrote:
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

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.
*****************************
Jul 17 '05 #3
$_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" <no*****@web.de> wrote in message
news:42***************@news.cs.tu-berlin.de...
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

Jul 17 '05 #4
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

Jul 17 '05 #5
"Daniel Loose" wrote:
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


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
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Robert Tarantino | last post: by
13 posts views Thread by Niki Kovacs | last post: by
5 posts views Thread by Morten | last post: by
5 posts views Thread by =?Utf-8?B?SmVycnkgQw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.