title: require_once function error when creating webpage in new folder
body: <p>I am running wamp64 to locally host my website (it is a vbulletin forums used for testing if that helps at all). </p>
  
  <p>I am trying to create a new webpage that is located in a subfolder instead of the root of the website, however I am running into errors.
  The webpage I am trying to create is the index.php webpage inside of the addons folder.</p>
  
  <p>My file structure is:</p>
  
  <blockquote>
    <p>C: <br>
    -wamp64 <br>
    --www (website root) <br>
    --global.php <br>
    ---addons <br>
    ----index.php <br>
    ----images <br>
    ---includes <br>
    ----config.php</p>
  </blockquote>
  
  <p>The code I am using for addons - index.php is:</p>
  
  <pre><code>    &lt;?php 
            error_reporting(E_ALL &amp; ~E_NOTICE); 
  
         define('NO_REGISTER_GLOBALS', 1); 
         define('THIS_SCRIPT', 'addons'); 
  
         $phrasegroups = array(); 
  
         $specialtemplates = array(); 
  
         $globaltemplates = array( 
         'ADDONSTESTPAGE' 
         ); 
  
         $actiontemplates = array(); 
  
         require_once('/../global.php');
  
         eval('$navbar = "' . fetch_template('navbar') . '";'); 
         eval('print_output("' . fetch_template('ADDONSTESTPAGE') . '");'); 
  
     ?&gt; 
  </code></pre>
  
  <p>When I create a new page in the www folder, it works perfectly (except I use <code>require_once('/global.php');</code> instead of <code>require_once('/../global.php');</code>.
  However, because this is in a subfolder, I am running into the following error due to the files that the global.php is requiring once having their own require_once functions inside of them and those files have their own require_once functions inside of them, etc.</p>
  
  <p>Here is the error I am getting now when I go to localhost/addons/:</p>
  
  <blockquote>
    <p>Warning: require_once(C:\wamp64\www\addons/includes/init.php): failed
    to open stream: No such file or directory in C:\wamp64\www\global.php
    on line 20</p>
    
    <p>Fatal error: require_once(): Failed opening required
    'C:\wamp64\www\addons/includes/init.php'
    (include_path='.;C:\php\pear') in C:\wamp64\www\global.php on line 20</p>
  </blockquote>
  
  <p>Here are lines 13-20 of global.php:</p>
  
  <pre><code>// identify where we are
  define('VB_AREA', 'Forum');
  
  define('CWD', (($getcwd = getcwd()) ? $getcwd : '.'));
  
  //     #############################################################################
  // Start initialisation
  require_once(CWD . '/includes/init.php');
  </code></pre>
  
  <p>How do I solve this without messing up other files that use the global.php file? I have heard realpath is a common solution for this, but I am new to php and not exactly sure how to use it in this scenario.</p>
  
  <p>All help is appreciated, thank you very much, if you need any more information feel free to ask!</p>
  
  <p>Okay I was able to solve that error by changing <code>require_once(CWD . '/includes/init.php');</code> to <code>require_once(__DIR__ . '/includes/init.php');</code>.</p>
  
  <p>Now I am getting this error:</p>
  
  <blockquote>
    <p>Warning: require_once(C:\wamp64\www\addons/includes/class_core.php): failed to open stream: No such file or directory in C:\wamp64\www\includes\init.php on line 51</p>
    
    <p>Fatal error: require_once(): Failed opening required 'C:\wamp64\www\addons/includes/class_core.php' (include_path='.;C:\php\pear') in C:\wamp64\www\includes\init.php on line 51</p>
  </blockquote>
  
  <p>Class_core.php exists in the includes folder.</p>
  
  <p>Line 51 of init.php is:</p>
  
  <pre><code>require_once(CWD . '/includes/class_core.php');
  </code></pre>
  
  <p>I tried changing it to <code>require_once(__DIR__ . '/includes/class_core.php');</code> but it breaks the entire website.</p>