mimecorg / webissues

WebIssues team collaboration system.
https://webissues.mimec.org/
GNU Affero General Public License v3.0
60 stars 14 forks source link

Warning issued for array key SCRIPT_FILENAME #83

Open durangod opened 3 weeks ago

durangod commented 3 weeks ago

PHP Warning: Undefined array key "SCRIPT_FILENAME" in /home/username/sitename/subdir/system/bootstrap.inc.php on line 141

I understand this is just a warning and i did try to post this on your forum but i was not able to register on your forum because i never got a verify email from the forum, so i am posting here.

First thanks for doing this script, i really like it... :)

This warning i believe is caused because server SCRIPT_FILENAME is not always populated on some servers, so it needs to be qualified first.

in bootstrap.inc.php you have the following code

public static function getScriptPath()
    {
        if ( defined( 'WI_SCRIPT_PATH' ) )
            return WI_SCRIPT_PATH;

        $path = $_SERVER[ 'SCRIPT_FILENAME' ];

        $real = realpath( $path );
        if ( $real )
            $path = $real;
        $path = str_replace( '\\', '/', $path );

        return $path;
    }

$path value needs to be wrapped inside an if statement to be sure that SCRIPT_FILENAME has a value. Im not sure what value (referrer) it should have or i would do the code for you and post it here. I just wanted to give you a heads up so you know this was causing a warning without the if statement. :)

I think this may work

  public static function getScriptPath()
    {
        if ( defined( 'WI_SCRIPT_PATH' ) )
            return WI_SCRIPT_PATH;

        //dave mod

        if(!empty($_SERVER[ 'SCRIPT_FILENAME' ]))
        {

          $path = $_SERVER[ 'SCRIPT_FILENAME' ]; 

        }else{

               $path = __FILE__;

             }

        //original code 
        //$path = $_SERVER[ 'SCRIPT_FILENAME' ];

        //end mod

        $real = realpath( $path );
        if ( $real )
            $path = $real;
        $path = str_replace( '\\', '/', $path );

        return $path;
    }
mimecorg commented 2 weeks ago

To be honest it's the first time I see $_SERVER[ 'SCRIPT_FILENAME' ] not being defined. What server do you use?

I'm not sure if using __FILE__ instead will work correctly because it will refer to boostrap.inc.php, not the script which is being executed.

durangod commented 2 weeks ago

Server config is

cPanel Version | 118.0 (build 12) Apache Version | 2.4.59 MySQL Version | 10.6.18-MariaDB-cll-lve-log Architecture | x86_64 Operating System | linux Perl Version | 5.26.3 Kernel Version | 4.18.0-513.18.1.lve.el8.x86_64 PHP Version | 8.1

Just FYI, i have seen that warning come up with other processes as well from different files, so it appears it may be a php issue or some global issue.