title: Change working directory
body: <p>Sorry for asking again, but I really need help. I have header.php in the root/lib which is including header_sub.php in the same directory. Normally files in root can directly include them by this code:</p>
  
  <pre><code>include_once('lib/header.php');
  </code></pre>
  
  <p>but now i have example.php in a sub-directory /blog, if i use these</p>
  
  <pre><code>include_once(../'lib/header.php');  or 
  include_once($_SERVER['DOCUMENT_ROOT'].'/lib/header.php');  or 
  include_once(dirname(__FILE__).'/lib/header.php');
  </code></pre>
  
  <p>header_sub.php would not be included correctly.</p>
  
  <p>Is there a way to include header.php and header_sub.php without modifying them?</p>
  
  <p>Some body suggested to use these:</p>
  
  <pre><code>$oldcwd = getcwd(); // Save the old working directory
      chdir("../"); // Moves up a folder, so from /blog to /
      include("header.php"); // Include the file with the working directory as if the header file were being loaded directly, from it's folder
      chdir($oldcwd); // Set the working directory back to before
  </code></pre>
  
  <p>However, even i can see the current url is root directory after chdir(), it still includes this root/blog/lib......</p>