How can PHP developers prevent all PHP pages from being indexed by search engines except for the index.php page?

To prevent all PHP pages from being indexed by search engines except for the index.php page, developers can add a meta tag with a robots directive in the head section of each PHP page they want to exclude from indexing. This meta tag should have a value of "noindex, nofollow" to instruct search engine crawlers not to index or follow the page. Additionally, developers can use a conditional statement in the PHP code to check if the current page is not the index.php page and then output the meta tag accordingly.

<?php
if(basename($_SERVER['PHP_SELF']) !== 'index.php') {
    echo '<meta name="robots" content="noindex, nofollow">';
}
?>