Welcome Guest, Not a member yet? Register   Sign In
Bug in ci/index.php concerning server path?

I've had some issues with backslashes appearing in my $system_folder (BASEPATH).
I'm developing on Windows XP using WAMPSERVER 2.0, and Codeigniter 1.7.2.

I've set system folder as indicated by the manual:
$system_folder = "system";


<?php echo BASEPATH; ?>

Gives me the following result:


To solve this I added the "swap directory seperator to unix style" into line 68 in ci/index.php:

if (strpos($system_folder, '/') === FALSE)
    if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
        $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
            // Swap directory separators to Unix style for consistency
            $system_folder = str_replace("\\", "/", $system_folder);

BASEPATH now gives me the expected result:


Is this a bug?

That's why PHP as invented the constant DIRECTORY_SEPARATOR, which you should use instead of hardcoding a (back)slash to be used in a path...

Thanks for the heads up, but shouldn't Codeigniter include this by default in ci/index.php?

*EDIT* I also read the comment on php.net regarding that DIRECTORY_SEPARATOR is uncessary since Windows will accept forward slash, but I guess its good for exploding a path though.

For PHP, it's not a problem to use Unix style directory separators in a Windows environment. Problem starts with user input (who are used to C:\), and certain PHP functions, like realpath, that return backslashes on a Windows platform.

I would say that CI should work uniformly, so on a Windows platform, make sure everything is using backslashes, and on other platforms, use forward slashes. In which case all hardcoded slashes need to be replaced by DIRECTORY_SEPARATOR. And yes, in core code CI should take care of this.

Theme © iAndrew 2016 - Forum software by © MyBB