title: Getting the base path/URL
body: <p>I am trying to get the base path of the documents through a function as I do not want to find the paths like <code>../folder1/folder2/mypage.php</code> or <code>../../../folder1/folder2/somepage.php</code>.</p>
  
  <p>Therefore I tried...</p>
  
  <pre><code>function getBaseUrl() {
  // output: /myproject/index.php
  $currentPath = $_SERVER['PHP_SELF'];
  
  // output: Array ( [dirname] =&gt; /myproject [basename] =&gt; index.php [extension] =&gt; php [filename] =&gt; index )
  $pathInfo = pathinfo($currentPath);
  
  // output: localhost
  $hostName = $_SERVER['HTTP_HOST'];
  
  // output: http://
  $protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https://'?'https://':'http://';
  
  // return: http://localhost/myproject/
  return $protocol.$hostName.$pathInfo['dirname']."/";
  }
  </code></pre>
  
  <p>Then i give write the code...</p>
  
  <pre><code>$base = getBaseUrl();
  require_once $base.'_include/db/qry.php';
  require_once $base.'_include/db/functions.php';
  </code></pre>
  
  <p>Both the files <code>qry.php</code> &amp; <code>functions.php</code> is in <code>http://localhost/mysite/_include/db/</code></p>
  
  <p>While i run the page, error shows ...</p>
  
  <pre><code>Warning: require_once(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in C:\xampp\htdocs\mysite\_include\header.php on line 9
  
  Warning: require_once(http://localhost/mysite/_include/db/qry.php): failed to open stream: no suitable wrapper could be found in C:\xampp\htdocs\mysite\_include\header.php on line 9
  
  Fatal error: require_once(): Failed opening required 'http://localhost/mysite/_include/db/qry.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\mysite\_include\header.php on line 9
  </code></pre>
  
  <p>I tried by echoing the getBaseUrl() like <code>echo $base;</code> and it is showing the right path i.e. <code>http://localhost/mysite/</code>.</p>
  
  <p>What should I do ?</p>