Connecting Tech Pros Worldwide Help | Site Map

How to detect local host?

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 01:29 PM
Daniel Loose
Guest
 
Posts: n/a
Default 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

  #2  
Old July 17th, 2005, 01:29 PM
Ewoud Dronkert
Guest
 
Posts: n/a
Default 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/
  #3  
Old July 17th, 2005, 01:29 PM
Chuck Anderson
Guest
 
Posts: n/a
Default 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.
*****************************
  #4  
Old July 17th, 2005, 01:29 PM
Tony Marston
Guest
 
Posts: n/a
Default 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]


  #5  
Old July 17th, 2005, 01:29 PM
chotiwallah
Guest
 
Posts: n/a
Default 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

  #6  
Old July 17th, 2005, 01:30 PM
steve
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.