Welcome Guest, Not a member yet? Register   Sign In
index.php, system_folder variable and multisite installation on windows
#1

[eluser]Unknown[/eluser]
I use Windows in my home and works station (producer server will use linux Smile). My CodeIgniter instalation is:

“C:\www-root\codeigniter\” that contain the kernel of CodeIgniter.

“C:\www-root\www.example.com\” that contain the index.php file and the content of application folder. See demo.javierav.com/CI001.jpg for image of folders.

In index.php I have:

$system_folder = “c:\www-root\codeigniter”;
$application_folder = “c:\www-root\www.example.com”;

If I access to http://localhost/www.example.com url I will obtain the following php error:

“Fatal error: require_once() [function.require]: Failed opening required ‘C:\www-root\www.example.com/c:\www-root\codeigniter/codeigniter/CodeIgniter.php’ (include_path=’.;C:\Archivos de programa\xampp\php\pear\’) in C:\www-root\www.example.com\index.php on line 133”

Where is the problem? In index.php on line 65 we have this: “if (strpos($system_folder, ‘/’) === FALSE)” and would have to have “if (strpos($system_folder, ‘/’) === FALSE AND strpos($system_folder, ‘\\’) === FALSE)”

With this modification, my installation works fine. Is this a bug?

Regards,

Javier Aranda

P.D Sorry for my bad english. I'm spanish.
#2

[eluser]Seppo[/eluser]
Why don´t you use /, instead of \ ? It will also work on windows...
Although I think CI should change the '/' for DIRECTORY_SEPARATOR to avoid this issues
#3

[eluser]Michael Wales[/eluser]
You should use relative paths for the system_folder and application_folder variables.

I pretty much do exactly the same as you:

D:\xampp\htdocs\system
D:\xampp\htdocs\[folder-for-site]\[contents of application folder]
D:\xampp\htdocs\[folder-for-site]\index.php

In index.php:
Code:
$system_folder = '../system';
$application_folder = './';
#4

[eluser]tonanbarbarian[/eluser]
I have found that I can use absolute paths and it works fine

Interesting thing was when I first downloaded CI 6 months ago I had to use relative paths.
Not sure but I think there have been some subtle changes to the index.php file that have been modified in the CI 1.5.4 version since its original release. I may not be right but it seems that way

make sure that you have the following
Code:
/*
|---------------------------------------------------------------
| SET THE SERVER PATH
|---------------------------------------------------------------
|
| Let's attempt to determine the full-server path to the "system"
| folder in order to reduce the possibility of path problems.
| Note: We only attempt this if the user hasn't specified a
| full server path.
|
*/
if (strpos($system_folder, '/') === FALSE)
{
    if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
    {
        $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
    }
}
else
{
    // Swap directory separators to Unix style for consistency
    $system_folder = str_replace("\\", "/", $system_folder);
}

With that in the index.php I find I can use absolute paths

I also always use windows paths with / rather than \\
#5

[eluser]John_Betong[/eluser]
Quote:In index.php I have:

$system_folder = “c:\www-root\codeigniter”;
$application_folder = “c:\www-root\www.example.com”;

If I access to http://localhost/www.example.com url I will obtain the following php error:

“Fatal error: require_once() [function.require]: Failed opening required ‘C:\www-root\www.example.com/c:\www-root\codeigniter/codeigniter/CodeIgniter.php’ (include_path=’.;C:\Archivos de programa\xampp\php\pear\’) in C:\www-root\www.example.com\index.php on line 133”
 
Try solving the first Fatal error: by changing this line:
$system_folder = “codeigniter”;

This will make a valid include path:
‘C:\www-root\www.example.com/codeigniter/CodeIgniter.php’
 
 
#6

[eluser]Unknown[/eluser]
Hello.

Quote:Why don´t you use /, instead of \ ? It will also work on windows…
Thanks, I did not know that I can use "/" for windows path. :-)

Michael, thanks. I don't like use relative path. Really, with my mod on index.php my installation works fine. Now, I will change the directory separator to "/".

tonanbarbarian, I have downloaded Codeigniter yesterday from download page of this site. I think that these are the lastest version of CI, no?

Many thanks to all. ;-)

Regards,

Javier Aranda
#7

[eluser]xadio[/eluser]
Bug in Line 65 of index.php. Affects WINDOWS box users who supply full path using '\\' instead of '/'.

Bug:
Code:
if (strpos($system_folder, '/') === FALSE)

Fix:
Code:
if (strpos($system_folder, DIRECTORY_SEPARATOR) === FALSE)

However, I don't think the function is necessary or the condition should be redefined because all it is searching for is a slash. Consider the following examples.

Code:
$system_folder = 'system'; # OK
$system_folder = 'codeigniter/system'; # Not OK

This function also implies that the index.php is somewhere in the path of the codeigniter system directory. Now for a normal install I don't think this makes a difference, but if another like I wish to place my CodeIgniter system directory in a completely different location than the index.php then it will matter.

It would be nice if it were mentioned that "the index.php needs to be in the CI system path unless a full path is specified" in http://ellislab.com/codeigniter/user-gui...index.html .
#8

[eluser]Derek Jones[/eluser]
xadio, I merged your report with this existing thread from a few days ago. Please see the comments above.
#9

[eluser]xadio[/eluser]
Quote:xadio, I merged your report with this existing thread from a few days ago. Please see the comments above.

Thanks Derek, I didn't take a lot of effort to search if this existed so my apologies to the forum members.

Although slight as it is, I should probably use '/' instead of '\\' because it is replaced either way. However, the str_replace function exists so I would assume this was an intended possibility. If not then it should be reflected in the code and the User Guide.

I still stand by my point that this is a bug. The definition of the conditional does not work for what appear to be intended.
Code:
if(TRUE){} // This is just to correct the php highlight problem

// Note: If needle is not found, strpos() will return boolean FALSE.
//       So a string such as "C:\www\codeigniter\system" will return the
//       boolean FALSE making the conditional TRUE.
if (strpos($system_folder, '/') === FALSE) {...}
//       So when does the following execute?  When a $system_folder equals
//       "/www/codeigniter/system".  Then this function is useless for its
//       intended purpose. The other situation seems unlikely though. When would
//       someone do one of the following?
//       "C:/www\codeigniter\system"
//       "C:\www/codeigniter\system"
//       This means the following code is unnecessary unless these are used:
//       "/www\codeigniter/www"
//       "\www/codeigniter/www"
else
{
  $system_folder = str_replace('\\', '/', $system_folder);
}

I should wait to post this later as I am on a *nix box right now and cannot test the following on a win machine, but I won't wait. Wink Please take it with/as a grain of salt.

Code:
if(TRUE){} // This is just to correct the php highlight problem

// This is a few more lines of code, but I believe this adequately does what was intentionally desired
//  for both *nix and windows. Please note that on BSD systems realpath() doesn't fail if only the last path
//  component doesn't exist, while other systems will return FALSE.

// Function 'realpath' exists then handle *nix and win absolute paths
if (function_exists('realpath') &&
    (DIRECTORY_SEPARATOR == '/'  && strpos($system_folder, '/') !== 0) ||
    (DIRECTORY_SEPARATOR == '\\' && strpos($system_folder, ':') !== 1)) { //Not sure if Windows allows dirs with :

  // Extract path __FILE__ then create a realpath of `pwd`/$system_folder
  if (($dirpath = realpath(dirname(__FILE__)) . '/') !== FALSE && ($realpath = realpath($dirpath . '/' . $system_folder)) !== FALSE) {
    $system_folder = $realpath;
  }
  else if (isset($dirpath)) {
    die("\$system_folder [$system_folder] does not exist in \"$dirpath\".");
  }
}

// Swap directory separators to Unix style for consistency
$system_folder = str_replace("\\", "/", $system_folder);

//Double check that file exists; especially for BSD
if (!file_exists($system_folder)) {
  die("\$system_folder [$system_folder] does not exist.");
}

//Clear cache just incase
clearstatcache();

Benchmarks (seconds):
Code:
Test: /tmp/absolute_exists
----
Old: 6.2E-5
New: 4.5E-5

Test: relative_exists
----
Old: 4.1E-5
New: 3.6E-5

Test: /absolute_notexists
----
Old: 7.99999999998E-6
New: 1.3E-5

Test: relative_notexists
----
Old: 1.9E-5
New: 2.3E-5

The benchmarks above are the worst case scenario I could come up with after running it numerous times.

So there is slight decrease in time for working cases while an increase in functionality, ignoring failed cases as it doesn't impact the speed of the overall system. Please note that I have not tested this in Windows, but I will try and report back later.

If you want the php with benchmarks to test yourself just let me know.

Please critique if you see an error in my logic/code.
#10

[eluser]xadio[/eluser]
Just tested in windows and works flawlessly. However two small changes for consistency in error messages.

Change:
Code:
if (($dirpath = realpath(dirname(__FILE__)) . '/') !== FALSE && ($realpath = realpath($dirpath . '/' . $system_folder)) !== FALSE) {

To:
Code:
if (($dirpath = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR) !== FALSE && ($realpath = realpath($dirpath . DIRECTORY_SEPARATOR . $system_folder)) !== FALSE) {

Side note:

I like to define the DIRECTORY_SEPARATOR as DS. Like such:
Code:
define(DS, DIRECTORY_SEPARATOR);

If you do this, just replace all the instances of DIRECTORY_SEPARATOR to DS. (Save line space Smile )




Theme © iAndrew 2016 - Forum software by © MyBB