How can PHP be used to dynamically load different pages based on URL parameters?
To dynamically load different pages based on URL parameters in PHP, you can use the $_GET superglobal array to retrieve the parameter value from the URL and then include the corresponding page based on that value. This allows you to create a single PHP script that can handle multiple pages based on the URL parameters.
<?php
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
switch ($page) {
case 'about':
include 'about.php';
break;
case 'contact':
include 'contact.php';
break;
default:
include 'home.php';
break;
}
?>
Related Questions
- How can the performance difference between a local server like XAMPP and a hosting provider like bplaced.net be investigated?
- What are the advantages of using a while loop instead of a do-while loop in PHP code?
- What are common issues when trying to move posts or threads in a PHP forum, and how can they be resolved?