Correcting “USU5 could not find a valid base filename, please inform the developer. in …”

I upgraded this osCommerce contribution after finding a small bug, and got this error while running an utility I wrote.

For a better explanation, I usually write scripts to help updating the store, cleaning databases, or even generating google sitemaps, but keep these scripts is a subdirectory of  the main script, to avoid messing too much and forgetting to delete potentially dangerous scripts.

So, when I was trying to run to insert a new option to a batch of products, I had this error displayed:

"Warning:  USU5 could not find a valid base filename, please  inform the developer. in ..."

Sure enough, this “bug” was located in the file application_top.php, in a new function added in r119. As the problem is due to this script’s location being outside the main dir, the solution was quite simple.  I added a few lines checking if the directory in use is different from the catalog’s dir, and simply returned a correct value overriding the function. In other words:

Locate in includes/application_top.php the lines

        /**
	* USU5 function to return the base filename
	*/
	function usu5_base_filename() {
		// Probably won't get past SCRIPT_NAME unless this is reporting cgi location
		$base = new ArrayIterator( array( 'SCRIPT_NAME', 'PHP_SELF', 'REQUEST_URI', 'ORIG_PATH_INFO', 'HTTP_X_ORIGINAL_URL', 'HTTP_X_REWRITE_URL' ) );
		while ( $base->valid() ) {
			if ( array_key_exists(  $base->current(), $_SERVER ) && !empty(  $_SERVER[$base->current()] ) ) {
				if ( false !== strpos( $_SERVER[$base->current()], '.php' ) ) {
					preg_match( '@[a-z0-9_]+\.php@i', $_SERVER[$base->current()], $matches );
					if ( is_array( $matches ) && ( array_key_exists( 0, $matches ) )
																		&& ( substr( $matches[0], -4, 4 ) == '.php' )
																		&& ( is_readable( $matches[0] ) || ( false !== strpos( $_SERVER[$base->current()], 'ext/modules/' ) ) ) ) {
						return $matches[0];
					}
				}
			}
			$base->next();
		}
		// Some odd server set ups return / for SCRIPT_NAME and PHP_SELF when accessed as mysite.com (no index.php) where they usually return /index.php
		if ( ( $_SERVER['SCRIPT_NAME'] == '/' ) || ( $_SERVER['PHP_SELF'] == '/' ) ) {
			return 'index.php';
		}
		trigger_error( 'USU5 could not find a valid base filename, please inform the developer.', E_USER_WARNING );
	} // End function
// set php_self in the local scope
	$PHP_SELF = usu5_base_filename();

and change for

        /**
	* USU5 function to return the base filename
	*/
	function usu5_base_filename() {
		// Probably won't get past SCRIPT_NAME unless this is reporting cgi location
		$base = new ArrayIterator( array( 'SCRIPT_NAME', 'PHP_SELF', 'REQUEST_URI', 'ORIG_PATH_INFO', 'HTTP_X_ORIGINAL_URL', 'HTTP_X_REWRITE_URL' ) );
		while ( $base->valid() ) {
			if ( array_key_exists(  $base->current(), $_SERVER ) && !empty(  $_SERVER[$base->current()] ) ) {
				if ( false !== strpos( $_SERVER[$base->current()], '.php' ) ) {
					// ignore processing if this script is not running in the catalog directory
					if( dirname($_SERVER[$base->current()]).'/' != DIR_WS_CATALOG){
						return $_SERVER[$base->current()];
					}
					preg_match( '@[a-z0-9_]+\.php@i', $_SERVER[$base->current()], $matches );
					if ( is_array( $matches ) && ( array_key_exists( 0, $matches ) )
																		&& ( substr( $matches[0], -4, 4 ) == '.php' )
																		&& ( is_readable( $matches[0] ) || ( false !== strpos( $_SERVER[$base->current()], 'ext/modules/' ) ) ) ) {
						return $matches[0];
					}
				}
			}
			$base->next();
		}
		// Some odd server set ups return / for SCRIPT_NAME and PHP_SELF when accessed as mysite.com (no index.php) where they usually return /index.php
		if ( ( $_SERVER['SCRIPT_NAME'] == '/' ) || ( $_SERVER['PHP_SELF'] == '/' ) ) {
			return 'index.php';
		}
		trigger_error( 'USU5 could not find a valid base filename, please inform the developer.', E_USER_WARNING );
	} // End function
// set php_self in the local scope
	$PHP_SELF = usu5_base_filename();
 
Let me know if yout tried this modification.

Tags:

Leave a Reply

You must be logged in to post a comment.