How can PHP be used to dynamically change the navigation bar on different pages?
To dynamically change the navigation bar on different pages using PHP, you can create a separate PHP file that contains the navigation bar code and then include this file in each page where you want the navigation bar to appear. You can use PHP to determine which page is currently being viewed and highlight the corresponding link in the navigation bar.
// navigation.php
<nav>
<ul>
<li><a href="index.php" <?php if(basename($_SERVER['PHP_SELF']) == 'index.php') { echo 'class="active"'; } ?>>Home</a></li>
<li><a href="about.php" <?php if(basename($_SERVER['PHP_SELF']) == 'about.php') { echo 'class="active"'; } ?>>About</a></li>
<li><a href="services.php" <?php if(basename($_SERVER['PHP_SELF']) == 'services.php') { echo 'class="active"'; } ?>>Services</a></li>
<li><a href="contact.php" <?php if(basename($_SERVER['PHP_SELF']) == 'contact.php') { echo 'class="active"'; } ?>>Contact</a></li>
</ul>
</nav>
```
In your individual pages, you can include the navigation bar like this:
```php
<?php include 'navigation.php'; ?>