1

The video illustrating the problem in real time is available here:

link: https://www.youtube.com/watch?v=IaTJNS31w6A&feature=youtu.be

I have been learning web-development. Newbie in PHP.

I created a site in a local server WAMP. By default WAMP uses PHP 5.6. When the version is changed to 7.2.4, the site doesn't work. The warnings are:

Warning: include_once(/app/config.inc.php): failed to open stream: No such file or directory in E:\wamp64\www\ziurfreelance2\index.php on line 3

and

Warning: include_once(): Failed opening '/app/config.inc.php' for inclusion (include_path='.;/path/to/php/pear/.;') in E:\wamp64\www\ziurfreelance2\index.php on line 3

I changed the include_path in php.ini, just trying to find a solution. It didn't work, though.

The files are correctly placed (in the video you can see the site works just fine) and nothing more is done but change the PHP versions.

The files are correctly placed (in the video you can see the site works just fine), only the PHP versions are different.

The project' tree here: https://i.pinimg.com/originals/c9/52/68/c9526844ba7a80ba63baeaccab1965e7.png

i really hope you can help me. Maybe, as I readed in some place, the bug is related to apache, that info was not very clear and specific.

Even defining a constant in the same file (note that the include_once calls the config.inc.php where all the other used constants are) and maybe it works, but Why does the version break it?

Here's the index.php (placed in the root directory):

<?php

include_once "/app/config.inc.php";

$componentes_url = parse_url($_SERVER["REQUEST_URI"]);
$ruta = $componentes_url['path'];
$partes_ruta = explode("/", $ruta);
$partes_ruta = array_filter($partes_ruta);
$partes_ruta = array_slice($partes_ruta,0);

$ruta_elegida = '/paginas/404.php';


if($partes_ruta == null){

$ruta_elegida = '/paginas/home.php';

}

//para subpaginas de primer nivel

else if(count($partes_ruta) == 1){

    switch($partes_ruta[0]){

        case 'aviso-legal';
            $ruta_elegida = '/paginas/aviso-legal.php';
            break;

        case 'sobre-mi';
            $ruta_elegida = '/paginas/bio.php';
            break;

        case 'blog';
            $ruta_elegida = '/paginas/blog.php';
            break;

        case 'contacto';
            $ruta_elegida = '/paginas/contacto.php';
            break;

        case 'diseno-grafico';
            $ruta_elegida = '/paginas/diseno-grafico.php';
            break;

        case 'diseno-web';
            $ruta_elegida = '/paginas/diseno-web.php';
            break;

        case 'fotografia';
            $ruta_elegida = '/paginas/fotografia.php';
            break;

        case 'modelado';
            $ruta_elegida = '/paginas/modelado.php';
            break;

        case 'video-y-animacion';
            $ruta_elegida = '/paginas/video-y-animacion.php';
            break;

        case 'ziur11235813213455fotos';
            $ruta_elegida = '/paginas/subida-fotos.php';
            break;
        }

}

include_once $ruta_elegida;

And here the .htaccess:

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^.*$ ./index.php

Thx for your time.

Jeferson Ruiz
  • 19
  • 1
  • 6
  • whats your file tree? – DaFois May 19 '18 at 08:22
  • if your `include_once(/app/config.inc.php):` is on index.php who are on root folder. Just replace by `include_once(__DIR__.'/app/config.inc.php'):` – Yanis-git May 19 '18 at 08:26
  • Sorry, I couldn't make understandable the tree. The video is avaliable now, you can see the tree in it. ` – Jeferson Ruiz May 19 '18 at 08:34
  • @Yanis-git, thx for your answer, I'll try it. but ¿Why the change 5.6 to 7.2.4 make the original code dont work? – Jeferson Ruiz May 19 '18 at 08:52
  • @Yanis-git the solution your propose works just for the index.php, but dont work to the other pages. home.php make calls to files in other folder that are "brother" of its own folder. – Jeferson Ruiz May 19 '18 at 15:04
  • @DaFois here's [the tree](https://i.pinimg.com/originals/c9/52/68/c9526844ba7a80ba63baeaccab1965e7.png) The folder opens are the principal that make called each other – Jeferson Ruiz May 19 '18 at 15:10
  • maybe it's needed to see your .htaccess and your index.php – DaFois May 19 '18 at 15:51
  • @DaFois thx, I have edited the question with the two codes you are asking for, and the tree image – Jeferson Ruiz May 19 '18 at 18:01

3 Answers3

1

You should use __DIR__ magic constant to generate correct absolute paths for files. For example:

include_once __DIR__ . '/../app/config.inc.php';

getcwd() may give you unexpected results - it will return different value for these 2 calls:

php index.php
php myapp/index.php

since you're calling index.php from two different places. __DIR__ will always return the same value regardless of place from you're running PHP script.

rob006
  • 21,383
  • 5
  • 53
  • 74
0

slash / for path to root dir, so just remove slash / on your include path

include_once "app/config.inc.php";
-1

I could resolve this adding a constant in the beginning of index.php just like that:

define("RAIZ",getcwd());

and use it in all include callings, something like that:

include_once RAIZ."\app\config.inc.php";

And the site just work in both PHP versions. BUT, i have another problem, that still related to include_Path. I'll make a new Question about that.

This solutión doesn´t look very good to me, but for now, it's working.

Plz, if someone of you have a better idea or can tell me what's wrong with the versions, plz tell it me.

Thx again for your time.

Jeferson Ruiz
  • 19
  • 1
  • 6