PHP variable empty

Discussion in 'Installation/Configuration' started by Elfchen, Jul 28, 2007.

  1. Elfchen

    Elfchen New Member

    Hi!

    When I do the following:

    Code:
    <?echo $HTTP_SERVER_VARS['DOCUMENT_ROOT'];?>
    
    the output is empty ... why?

    PHP Notice: Undefined variable: HTTP_SERVER_VARS

    but what should be wrong here:

    Code:
    <?php $downdir="/downdir/"; include($HTTP_SERVER_VARS['DOCUMENT_ROOT'].$downdir."showit.php"); ?>
    
    on other servers with PHP5 it works without any problems ...

    *** confused again ***
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    The usage of the variable $HTTP_SERVER_VARS is deprecated, use the variable $_SERVER instead.
     
  3. Elfchen

    Elfchen New Member

    How to solve it?

    I can't rewrite all my scripts. I need it.

    Code:
    $HTTP_POST_FILES[ 'image' . $imgformat['id'] ];
    $HTTP_GET_VARS = stripslashes_array( $HTTP_GET_VARS );
    $HTTP_REFERER = str_replace( "http://", "", $HTTP_REFERER );
    ...
    
    I need to enable it - all my sites will not work without it.

    This did not help:

    Code:
        if( !ini_get( "register_globals" ) || get_magic_quotes_gpc() )
        {
          if($version < 4.1) {
            @extract( $HTTP_GET_VARS );
            @extract( $HTTP_POST_VARS );
            @extract( $HTTP_SERVER_VARS );
            @extract( $HTTP_COOKIE_VARS );
            @extract( $HTTP_ENV_VARS );
          }
          else {
            @extract( $_GET );
            @extract( $_POST );
            @extract( $_SERVER );
            @extract( $_COOKIE );
            @extract( $_ENV );
          }
        }
    
     
    Last edited: Jul 29, 2007
  4. larwilliams

    larwilliams New Member

    Did you try something like this

    Code:
    if (!isset($HTTP_SERVER_VARS)){
    // Depreciated variable HTTP_SERVER_VARS is not declared.. hack to populate it with information from $_SERVER
    $HTTP_SERVER_VARS = $_SERVER;
    }
    
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    You can enable the old style arrays in your php ini by changing the line:

    register_long_arrays = Off

    to:

    register_long_arrays = On

    and then restart the apache webserver.
     
  6. Elfchen

    Elfchen New Member

    will check your suggestion. i did it like that - but it did not work and i don't know why ... on other servers it works without any problems (same suse and same php version):

    Code:
        // Do some version handling stuff
        $full_version = preg_replace("/[^0-9\.]+/", "", phpversion());
        $version = $full_version - 0;
    
        if( get_magic_quotes_gpc() )
        {
          if($version < 4.1) {
            $HTTP_GET_VARS = stripslashes_array( $HTTP_GET_VARS );
            $HTTP_POST_VARS = stripslashes_array( $HTTP_POST_VARS );
            $HTTP_COOKIE_VARS = stripslashes_array( $HTTP_COOKIE_VARS );
          }
          else {
            $_GET = stripslashes_array( $_GET );
            $_POST = stripslashes_array( $_POST );
            $_COOKIE = stripslashes_array( $_COOKIE );
          }
        }
    
        if( !ini_get( "register_globals" ) || get_magic_quotes_gpc() )
        {
          if($version < 4.1) {
            @extract( $HTTP_GET_VARS );
            @extract( $HTTP_POST_VARS );
            @extract( $HTTP_SERVER_VARS );
            @extract( $HTTP_COOKIE_VARS );
            @extract( $HTTP_ENV_VARS );
          }
          else {
            @extract( $_GET );
            @extract( $_POST );
            @extract( $_SERVER );
            @extract( $_COOKIE );
            @extract( $_ENV );
          }
        }
    
    Tryed also register_long_arrays in /etc/php5/ ... and restarted apache, but same like before - no success.
     
    Last edited: Jul 30, 2007
  7. falko

    falko Super Moderator ISPConfig Developer

    Did you modify the correct php.ini? The correct php.ini is listed in the output of phpinfo().
     
  8. Elfchen

    Elfchen New Member

    think so, because it shows: Configuration File (php.ini) Path /etc/php5/apache2/php.ini
     
  9. Elfchen

    Elfchen New Member

    and ... have created two identical vhosts (only domain name different).

    then copied files from host a into /web on host b

    on host a all works well

    on hast b i get permanent php error. but the i have identical files (cp -r ...).

    Code:
    <?php
    $bs_mysql_handle = @mysql_connect($mysql['host'], $mysql['user'], $mysql['pass']);
    if(!$bs_mysql_handle) {
            dbError("connect");
            exit();
    };
    if (!mysql_select_db($mysql['db'], $bs_mysql_handle)) {
            dbError("db");
            exit();
    };
    ?>
    
    on vhost a - no error - works
    on vhost b:

    Code:
    [Mon Jul 30 21:33:25 2007] [error] [client 1.2.3.4] PHP Fatal error:  Call to undefined function dbError() in /home/www/web27/web/funktionen/funktionen.php on line 4
    
    i become completly silly here ... how can this happen that identical scripts did not work on identical hosts? both hosts are on same server. only domainname is different ...
     
    Last edited: Jul 30, 2007
  10. till

    till Super Moderator Staff Member ISPConfig Developer

    Is the php safemode setting identical in both websites e.g. on or off? Do you have any .htaccess files in the sites? You can see the .htaccess files only with the command "ls -la" and not just "ls".
     
  11. Elfchen

    Elfchen New Member

    thanks for fast response.

    here it is:

    server 2 (did not work):
    Code:
    ######################################
    # Vhost: www.domain.us:80
    ######################################
    #
    #
    <VirtualHost 88.x.y.125:80>
    <Directory "/home/www/web27/web">
    php_admin_flag register_globals on
    AllowOverride All
    </Directory>
    ServerName www.domain.us:80
    ServerAdmin [email protected]
    DocumentRoot /home/www/web27/web
    ServerAlias domain.us
    DirectoryIndex index.html index.htm index.php index.php5 index.php4 index.php3 index.shtml index.cgi index.pl index.jsp Default.htm default.htm
    ScriptAlias  /cgi-bin/ /home/www/web27/cgi-bin/
    AddHandler cgi-script .cgi
    AddHandler cgi-script .pl
    ErrorLog /home/www/web27/log/error.log
    AddHandler application/x-httpd-php .php .php3 .php4 .php5
    php_admin_flag safe_mode Off
    Alias /error/ "/home/www/web27/web/error/"
    ErrorDocument 400 /error/invalidSyntax.html
    ErrorDocument 401 /error/authorizationRequired.html
    ErrorDocument 403 /error/forbidden.html
    ErrorDocument 404 /error/fileNotFound.html
    ErrorDocument 405 /error/methodNotAllowed.html
    ErrorDocument 500 /error/internalServerError.html
    ErrorDocument 503 /error/overloaded.html
    AliasMatch ^/~([^/]+)(/(.*))? /home/www/web27/user/$1/web/$3
    AliasMatch ^/users/([^/]+)(/(.*))? /home/www/web27/user/$1/web/$3
    </VirtualHost>
    
    Server 1 (did work):
    Code:
    ######################################
    # Vhost: www.domain.com:80
    ######################################
    #
    #
    <VirtualHost 88.x.y.125:80>
    <Directory "/home/www/web12/web">
    php_admin_flag register_globals on
    AllowOverride All
    </Directory>
    ServerName www.domain.com:80
    ServerAdmin [email protected]
    DocumentRoot /home/www/web12/web
    ServerAlias domain.com
    DirectoryIndex index.html index.htm index.php index.php5 index.php4 index.php3 index.shtml index.cgi index.pl index.jsp Default.htm default.htm
    ScriptAlias  /cgi-bin/ /home/www/web12/cgi-bin/
    AddHandler cgi-script .cgi
    AddHandler cgi-script .pl
    ErrorLog /home/www/web12/log/error.log
    AddHandler application/x-httpd-php .php .php3 .php4 .php5
    php_admin_flag safe_mode Off
    Alias /error/ "/home/www/web12/web/error/"
    ErrorDocument 400 /error/invalidSyntax.html
    ErrorDocument 401 /error/authorizationRequired.html
    ErrorDocument 403 /error/forbidden.html
    ErrorDocument 404 /error/fileNotFound.html
    ErrorDocument 405 /error/methodNotAllowed.html
    ErrorDocument 500 /error/internalServerError.html
    ErrorDocument 503 /error/overloaded.html
    AliasMatch ^/~([^/]+)(/(.*))? /home/www/web12/user/$1/web/$3
    AliasMatch ^/users/([^/]+)(/(.*))? /home/www/web12/user/$1/web/$3
    </VirtualHost>
    
    Additional I have rechecked for any .htaccess files, but there aren't any .htaccess (only auth in a subdir). All files are identical (copied with cp -r). I changed only mysql-settings and replaced web12 with web27 in second server (path settings). The result is one works, the other not. I have never seen such a thing before. I already found a few strange things in case of the suhosin - but now that variables $_SERVER Document root are shown with phpinfo() but when using in script they are empty, and two identical servers, where one did work and the other not is really quite strange ... :confused:
     
  12. falko

    falko Super Moderator ISPConfig Developer

    Are both servers using the same IP address?
     
  13. Elfchen

    Elfchen New Member

    yes. server has only 1 ip address in use which is shared by all vhosts
     
  14. falko

    falko Super Moderator ISPConfig Developer

    I thought you were talking about multiple servers, not multiple vhosts... :confused: So you have to web sites on the same server, and PHP is working fine for one web site, but not for the other?
     
  15. Elfchen

    Elfchen New Member

    yes. 2 vhosts on one ispconfig server.

    the one and only difference is the tld-domain (one .com other .us).

    all files are copied via cp -r into other vhost.

    result:

    one vhost work
    other vhost did not work

    i have never seen such a thing before that why i ask the developer :)
     
  16. Elfchen

    Elfchen New Member

    I also tried to switch the hosts - means:

    first created com, second us
    then us later com

    - there I recognized that only always the host which was created first is working - no matter which domain it's using.
     
  17. falko

    falko Super Moderator ISPConfig Developer

    Can you post your full Vhosts_ispconfig.conf and mark the two vhosts?
     

Share This Page