file_exists() open_basedir restriction issues

If a server is configured with open_basedir restrictions (which most servers SHOULD be), the way you go about finding the ABSPATH causes all sorts of warning like the following:


Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/var/wp-config.php) is not within the allowed path(s): (/var/www/vhosts/americanyouth.com/httpdocs:/tmp) in /var/www/vhosts/americanyouth.com/httpdocs/wp-content/mu-plugins/custom_anti_spam.php on line 132

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/var/www/wp-config.php) is not within the allowed path(s): (/var/www/vhosts/americanyouth.com/httpdocs:/tmp) in /var/www/vhosts/americanyouth.com/httpdocs/wp-content/mu-plugins/custom_anti_spam.php on line 132

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/var/www/vhosts/wp-config.php) is not within the allowed path(s): (/var/www/vhosts/americanyouth.com/httpdocs:/tmp) in /var/www/vhosts/americanyouth.com/httpdocs/wp-content/mu-plugins/custom_anti_spam.php on line 132

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/var/www/vhosts/americanyouth.com/wp-config.php) is not within the allowed path(s): (/var/www/vhosts/americanyouth.com/httpdocs:/tmp) in /var/www/vhosts/americanyouth.com/httpdocs/wp-content/mu-plugins/custom_anti_spam.php on line 132

Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/americanyouth.com/httpdocs/wp-content/mu-plugins/custom_anti_spam.php:132) in /var/www/vhosts/americanyouth.com/httpdocs/wp-content/mu-plugins/custom_anti_spam.php on line 232

I see that you have $cas_abspath for that, but there's a much better solution, which is to start from the current directory and work backwards instead of starting at the root and working forward. The code looks like this:

// Determine the ABSPATH if it is not already defined (i.e., when called to generate the image)
if( ! defined( 'ABSPATH' ) && ! $cas_abspath )
{
$abspath = dirname( __FILE__ ) . '/';
while( ! file_exists( $abspath . "wp-config.php" ) ) {
$abspath = dirname( $abspath ) . '/';
}
if ( file_exists( $abspath . "wp-config.php" ) ) {
define( 'ABSPATH', $abspath, true );
}
}