I have a problem with one of my PHP applications. I use the following block of code to include my functions into the application:
// Opening the directory where the functions are located and reading the contents
if (is_dir(__FDIR__)){
if ($dh = opendir(__FDIR__)){
while (($file = readdir($dh)) !== false){
if ($file != "." && $file != "..") {
//include all files found in the functions directory
include_once(__FDIR__.$file);
}
}
closedir($dh);
}
}
which works fine normally but as soon as I load an URL with $_GET parameters in the URL i get the following warning:
Warning: readdir(): 11 is not a valid Directory resource in C:\xampp\htdocs\portcms\functions.php on line 6
Warning: closedir(): 11 is not a valid Directory resource in C:\xampp\htdocs\portcms\functions.php on line 16
the weird thing here is that the $_GET Parameters do not target the above code. they are passed to a different Block of code to select which content div should be loaded. in addition in another application where I use this setup it works perfectly without throwing any warnings.
edit: the nonworking example is as follows: in index.php i have the follwing code:
<?php
//starting the session;
session_start();
//getting required files;
require_once('fileloc.php'); //file locater
require_once(__CONFIG__); //config file;
require_once(__FUNCTIONS__); //function loader-file;
require_once(__CDIR__."class.db.php"); //database class for database manipulation (replace with class-loader?);
//verifying the logged on user;
$ver = login($_SESSION['username'], $_SESSION['pass']);
if (!isset($ver) || $ver != 1) {
//could not verify user, destroying session and return to login screen;
session_destroy();
header('location: login.php');
}
//building the page;
require_once(__MDIR__. "header.php");
if ($ver == 1) {
require_once(__MDIR__."main.php");
}
echo __FDIR__.'overview.php';
require_once(__MDIR__. "footer.php");
?>
which includes my config files aswell as my definition file (filelocater). it also includes main.php which has the following code in it:
<div class="container">
<div class="bar">
<p>welcome: <b><?php echo $_SESSION['username']; ?> | <a href="logout.php">logout</a></b></p>
</div>
<div class="nav">
<ul>
<li><a href="?mod=overview">overview</a></li>
<!--<li><a href="">settings*</a></li>-->
<li><a href="">pages</a></li>
<li><a href="">portfolio management</a></li>
<!--<li><a href="">themes*</a></li>
<li><a href="">users*</a></li>
<li><a href="">plugins*</a></li>-->
</ul>
</div>
<div class="main">
<?php
if (isset($_GET) && !empty($_GET['mod'])) {
clean_input($_GET['mod']);
include_once(__MDIR__.$mod.'.php');
}
?>
</div>
</div>
no if i log in index.php is loaded without ?mod=overview and all is peacy. as soon as i press the overview link to load the overview "mod" (which for now is an empty file containing just the word "test") i get the warnings.
to verify that there was no problem with my constant I exchanged FDIR in functions.php for a hardcoded filepath string to the directory. this did not resolve the warning either. another weird thing is that the functions seem to be loading like they should even though the warning occurs. for example the function that checks if the login is valid is loaded through this function. and it seems to load without problems
hope i have provided enough information. otherwise let me know so I can put up more Code.
also please note that I am new to Stackoverflow so might not have done everything right. I did however researched multiple similar problems on here and the the rest of the internet to find a solution.
thanks in advance