How to detect local host?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Loose

    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
  • Ewoud Dronkert

    #2
    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/

    Comment

    • Chuck Anderson

      #3
      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

      Integrity is obvious.
      The lack of it is common.
      *************** **************

      Comment

      • Tony Marston

        #4
        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

        This is Tony Marston's web site, containing personal information plus pages devoted to the Uniface 4GL development language, XML and XSL, PHP and MySQL, and a bit of COBOL




        "Daniel Loose" <noreply@web.de > wrote in message
        news:42a32bb1.1 4911159@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]


        Comment

        • chotiwallah

          #5
          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

          Comment

          • steve

            #6
            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

            Comment

            Working...