Add class active only on website root with PHP
<p>I included my header in every page which also contains the navigation which leads to the problem on how to add an active class to each nav element if the specific link gets clicked.</p>

<p>I found a working solution on the net.</p>

<p>I put this in my index.php on top:</p>

<pre><code>&lt;?php basename($_SERVER["REQUEST_URI"]) ?&gt;
</code></pre>

<p>For each link I do this:</p>

<pre><code>&lt;li&gt;&lt;a &lt;?php if (basename($_SERVER["REQUEST_URI"]) == "index.php") echo " class='active' ";?&gt; href="index.php"&gt;Start&lt;/a&gt;&lt;/li&gt;
</code></pre>

<p>Everything works fine but of course it doesn't work at the very start if you just enter the domain name like:</p>

<pre><code>www.mydomain.com
</code></pre>

<p>I tried:</p>

<pre><code>if (basename($_SERVER["REQUEST_URI"]) != " ")
</code></pre>

<p>But then it will stick with the active class all the time.</p>

<p>How can I add something like "if it's the root just give the "Start" link and only then the active class?</p>
