title: Php opendir() gives warning when using GET
body: <p>I have a problem with one of my PHP applications. I use the following block of code to include my functions into the application:</p>
  
  <pre><code>    // 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 != "." &amp;&amp; $file != "..") {
  
                      //include all files found in the functions directory
                      include_once(__FDIR__.$file);
  
                  }
  
              }
              closedir($dh);
           }
      }
  </code></pre>
  
  <p>which works fine normally but as soon as I load an URL with $_GET parameters in the URL i get the following warning:</p>
  
  <pre><code>    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
  </code></pre>
  
  <p>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.</p>
  
  <p>edit: the nonworking example is as follows:
  in index.php i have the follwing code:</p>
  
  <pre><code>    &lt;?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");
  
  ?&gt;
  </code></pre>
  
  <p>which includes my config files aswell as my definition file (filelocater).
  it also includes main.php which has the following code in it:</p>
  
  <pre><code>    &lt;div class="container"&gt;
  &lt;div class="bar"&gt;
      &lt;p&gt;welcome: &lt;b&gt;&lt;?php echo $_SESSION['username']; ?&gt; |  &lt;a href="logout.php"&gt;logout&lt;/a&gt;&lt;/b&gt;&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;div class="nav"&gt;
      &lt;ul&gt;
          &lt;li&gt;&lt;a href="?mod=overview"&gt;overview&lt;/a&gt;&lt;/li&gt;
          &lt;!--&lt;li&gt;&lt;a href=""&gt;settings*&lt;/a&gt;&lt;/li&gt;--&gt;
          &lt;li&gt;&lt;a href=""&gt;pages&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=""&gt;portfolio management&lt;/a&gt;&lt;/li&gt;
          &lt;!--&lt;li&gt;&lt;a href=""&gt;themes*&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=""&gt;users*&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=""&gt;plugins*&lt;/a&gt;&lt;/li&gt;--&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  
  &lt;div class="main"&gt;
  &lt;?php
      if (isset($_GET) &amp;&amp; !empty($_GET['mod'])) {
          clean_input($_GET['mod']);
  
          include_once(__MDIR__.$mod.'.php');
      }
  ?&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>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.</p>
  
  <p>to verify that there was no problem with my constant I exchanged <strong>FDIR</strong> 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</p>
  
  <p>hope i have provided enough information. otherwise let me know so I can put up more Code.</p>
  
  <p>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.</p>
  
  <p>thanks in advance</p>