How can PHP be used to control the flow of a website's navigation?

PHP can be used to control the flow of a website's navigation by using conditional statements to determine which page to display based on user input or other conditions. This can be achieved by checking variables, form submissions, or session data to redirect users to different pages or display different content. By using PHP to control navigation, you can create dynamic and interactive websites that respond to user actions.

<?php
// Check if a specific variable is set to determine which page to display
if(isset($_GET['page'])) {
    $page = $_GET['page'];
    
    switch($page) {
        case 'home':
            include 'home.php';
            break;
        case 'about':
            include 'about.php';
            break;
        case 'contact':
            include 'contact.php';
            break;
        default:
            include '404.php';
            break;
    }
} else {
    include 'home.php'; // Default page to display
}
?>