How can PHP be used to control the display of content based on the page being accessed?

To control the display of content based on the page being accessed in PHP, you can use conditional statements to check the current page URL or other identifiers and then show or hide specific content accordingly.

<?php
$current_page = $_SERVER['REQUEST_URI'];

if($current_page == '/page1.php'){
    // display content for page 1
    echo "Content for page 1";
} elseif($current_page == '/page2.php'){
    // display content for page 2
    echo "Content for page 2";
} else {
    // default content
    echo "Default content";
}
?>