What are some best practices for handling tab navigation in PHP with Bootstrap?

When using tab navigation in PHP with Bootstrap, it is important to ensure that the active tab is correctly highlighted based on the current page. This can be achieved by checking the current page URL and adding the 'active' class to the corresponding tab. Additionally, make sure to use proper HTML structure for tab navigation to work effectively.

<?php
$current_page = basename($_SERVER['PHP_SELF']);
?>

<ul class="nav nav-tabs">
  <li class="nav-item <?php echo ($current_page == 'page1.php') ? 'active' : ''; ?>">
    <a class="nav-link" href="page1.php">Page 1</a>
  </li>
  <li class="nav-item <?php echo ($current_page == 'page2.php') ? 'active' : ''; ?>">
    <a class="nav-link" href="page2.php">Page 2</a>
  </li>
  <li class="nav-item <?php echo ($current_page == 'page3.php') ? 'active' : ''; ?>">
    <a class="nav-link" href="page3.php">Page 3</a>
  </li>
</ul>