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

How to detect local host?

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
$_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

P: n/a
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

P: n/a
"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.