I can't echo the variables like $SERVER_ADDR and $PHP_SELF, $REMOTE_ADDR

It works on my liveserver but not on my localserver. so its no syntax error.
The function phpinfo() works and gives me these variables in its listtable.
I can also echo normal variables and strings.

I am using apache on win2000 with php4.1.1

I tried it with the php.exe and phpapachemodul.

    There´s been some changes in php 4.1.
    Look into your php.ini if register globals is on. I think if its in off, those variables don´t get registered.
    As for variables in general, create a script with phpinfo() in it. You´ll notice that a lot of variables changed, e.g. $SERVER_ADDR is now $_SERVER["SERVER_ADDR"]
    Look into the changelog on php.net, its described there why this was changed.

      • [deleted]

      "You´ll notice that a lot of variables changed, e.g. $SERVER_ADDR is now $_SERVER["SERVER_ADDR"]"

      Not completely true.
      $SERVER_ADDR is still $SERVER_ADDR.
      But., all the server vars used to be available in $HTTP_SERVER_VARS. PHP have decided to rename that array to $_SERVER.

      In 4.1.x, all the old options are still available, but they will be dropped in future releases.

      Accessing 'global' variables is never a good idea, always specify where you want to get the value from, because that will work on any installation of PHP:
      echo $HTTP_SERVER_VARS['SERVER_ADDR'];
      or in 4.1.x:
      echo $_SERVER['SERVER_ADDR'];

        Hmm, doesn´t that one vanish too like $PHP_SELF does when I turn globals off? Well, my mistake then 🙂

          • [deleted]

          Nope, register_globals just copies the vars from the $HTTP*VARS arrays to the global scope, but the original arrays are always available.

            $GLOBALS['PHP_SELF'] etc. will work.

              Write a Reply...