Search code examples
phprequire

PHP - require $file doesnt work - Failed opening required 'mod_login/.php'


first of all, thanks for your help.

I made a backend with /admin, you can enter these site with mod_sitename.php.

 $allowedForModul = checkAllowOfModuleByUserID(array('linkname' => 
 $_REQUEST['mod'], 'uid' => $_SESSION['s_user_id']));
     if ($allowedForModul OR in_array($_REQUEST['mod'], $allowedModules)) $file = "mod_" . $_REQUEST['mod'] . ".php";
     else $file = "mod_403.php";

Then I require the file with

 require $file;

The Error:

Fatal error: require(): Failed opening required 'mod_login/.php' (include_path='.:/usr/share/php') in /vagrant/admin/index.php on line 161 Call Stack

It's on PHP 7 with doctrine.


Solution

  • Well, it appears the value of $_REQUEST['mod'] is "login/", therefore "mod" . $_REQUEST['mod'] . ".php" evaluates to "mod_login/.php".

    Unless you have a folder called mod_login and a file in it called .php, the file won't be found.