1

I developed a website that runs perfectly on Linux, but when I try to run it on the Windows production server, the php script doesn't work. Everything that's in the code after this line doesn't do anything:

require_once __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'returner.php';

I thought that the proble could be related to the paths of the files, so I modified the code to use DIR and DIRECTORY_SEPARATOR to avoid any kind of problems with the paths. I tested if the path was working using file_exists and the file was located, but my code still does nothing when I try to run it on the Windows server.

/index.php includes /lib/returner.php

/lib/returner.php includes /lib/login.php

Code:

index.php:

...
div class="container" role="main">
    <?php
        require_once __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'returner.php';
        echo '<div class="page-header">';
        echo '<h1>' . returnSede() . '</h1>';
        ...

returner.php:

...
<?php
    require_once __DIR__ . DIRECTORY_SEPARATOR . 'login.php';
    $sede = $_POST['selectSede'];
...
efredz
  • 13
  • 2
  • 7

1 Answers1

0

It seems like your code should work.

Just in case, this answer on Stack Overflow might shed some light. I'll kind of summarize:

If you're only worried about Unix-based or Windows, hard coding the path with forward slashes ("C:/test.txt") will work.

There can be discrepancies due to what type of quote you use:

  • for instance, "\123" translates to "Q"
  • Windows requires "C:\\test.txt" or 'C:\test.txt' or "C:/test.txt"

Another answer on the same question suggests doing something like this:

define('DS','/');
define('BASE_ROOT',str_replace('\\',DS,dirname(__FILE__)));
require_once BASE_ROOT . DS . 'includes' . DS . 'init.php';
Community
  • 1
  • 1
Joseph Hansen
  • 12,665
  • 8
  • 50
  • 68
  • using \__DIR__ has the same result than using dirname(\_\_FILE__) and my code isn't using any normal or backslashes, I'm using DIRECTORY_SEPARATOR to avoid having a mess with / and \ depending on the platform. – efredz Dec 30 '14 at 19:58
  • From the documentation linked in those other answers, it seems that using DIRECTORY_SEPARATOR can have problems. The only counter-example I've read, however, was when using double quotes and DIRECTORY_SEPARATOR which can result in an unescaped backslash in double quotes which can give unexpected results. I'm curious to see what the actually fix for your situation is. – Joseph Hansen Dec 30 '14 at 21:58