 <p>This should work:</p> <pre><code>$a = get_included_files(); echo $a[0]; </code></pre> <p>Quote from <a href="http://php.net/manual/en/function.get-included-files.php" rel="nofollow"><code>get_included_files()</code></a> documentation:</p> <blockquote> <p>The script originally called is considered an "included file," so it will be listed together with the files referenced by include and family.</p> </blockquote> <h1>Test</h1> <pre><code>&lt;!-- main.php --&gt; &lt;?php include "middle.php"; ?&gt; &lt;!-- middle.php --&gt; &lt;?php include "inner.php"; ?&gt; &lt;!-- inner.php --&gt; &lt;?php var_dump(__FILE__, $_SERVER["PHP_SELF"], get_included_files()); ?&gt; </code></pre> <h1>Output</h1> <pre class="lang-none prettyprint-override"><code>string(21) "C:\inetpub\wwwroot\inner.php" string(9) "/main.php" array(3) { [0]=&gt; string(20) "C:\inetpub\wwwroot\main.php" &lt;-- this is what you are looking for [1]=&gt; string(22) "C:\inetpub\wwwroot\middle.php" [2]=&gt; string(21) "C:\inetpub\wwwroot\inner.php" } </code></pre>