What is the best practice for setting a default main page in PHP websites?
When setting a default main page in PHP websites, it is best practice to use a conditional statement to check if a specific page has been requested. If no page is specified, then the default main page should be displayed. This can be achieved by using the $_GET superglobal to retrieve the requested page parameter and setting a default page if it is not provided.
<?php
// Check if a specific page is requested
if(isset($_GET['page'])) {
$page = $_GET['page'];
} else {
// Set default main page
$page = 'home';
}
// Include the requested page
include($page . '.php');
?>
Keywords
Related Questions
- What best practices should be followed when handling sessions in PHP to ensure data persistence and security?
- Are there any specific PHP functions or methods that are recommended for handling daily visitor count data in PHP scripts?
- What are the potential pitfalls of using PHP echo statements to store HTML content in a variable?