CodeIgniter Forums
Bug in ci/index.php concerning server path? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Bug in ci/index.php concerning server path? (/showthread.php?tid=39832)



Bug in ci/index.php concerning server path? - El Forum - 03-22-2011

[eluser]Unknown[/eluser]
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";

Then..

Code:
<?php echo BASEPATH; ?>

Gives me the following result:

Code:
C:\wamp\www\ci/system

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

Code:
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:

Code:
C:/wamp/www/ci/system/

Is this a bug?


Bug in ci/index.php concerning server path? - El Forum - 03-22-2011

[eluser]WanWizard[/eluser]
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...


Bug in ci/index.php concerning server path? - El Forum - 03-22-2011

[eluser]Unknown[/eluser]
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.


Bug in ci/index.php concerning server path? - El Forum - 03-22-2011

[eluser]WanWizard[/eluser]
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.