If there are many pages share a same menu
include_once('common-menu.php');
But the menu should have some different for different page
Page A
<ul class="nav navbar-nav">
<li class="active"><a href="a.php">A Page</a></li>
<li><a href="b.php">B Page</a></li>
</ul>
Page B
<ul class="nav navbar-nav">
<li><a href="a.php">A Page</a></li>
<li class="active"><a href="b.php">B Page</a></li>
</ul>
I only know two solutions.
Solution 1: Server side to detect the URL then determine the output
<ul class="nav navbar-nav">
<li class="<? echo 'active'; ?>"><a href="a.php">A Page</a></li>
<li class=""><a href="b.php">B Page</a></li>
</ul>
<ul class="nav navbar-nav">
<li class=""><a href="a.php">A Page</a></li>
<li class="<? echo 'active'; ?>"><a href="b.php">B Page</a></li>
</ul>
Solution 2: Use js/jquery to detect the URL, and then change the class by js/jquery after the page loaded.
What is the best practice for this problem?
Is there any non-programmatic solution so that I don't need to use if/case/map to determine the active item?