What are the potential advantages of using the $_SERVER['SCRIPT_NAME'] variable in PHP for navigation highlighting?
Using the $_SERVER['SCRIPT_NAME'] variable in PHP for navigation highlighting allows you to easily determine which page is currently being accessed, enabling you to apply specific styling or highlighting to the corresponding navigation link. This can enhance user experience by providing visual feedback on the active page and helping users navigate the website more effectively.
<?php
$current_page = basename($_SERVER['SCRIPT_NAME']);
?>
<!-- Navigation menu example -->
<ul>
<li <?php if($current_page == 'index.php') echo 'class="active"'; ?>><a href="index.php">Home</a></li>
<li <?php if($current_page == 'about.php') echo 'class="active"'; ?>><a href="about.php">About</a></li>
<li <?php if($current_page == 'services.php') echo 'class="active"'; ?>><a href="services.php">Services</a></li>
<li <?php if($current_page == 'contact.php') echo 'class="active"'; ?>><a href="contact.php">Contact</a></li>
</ul>