How can PHP be used to display different content based on the URL parameters?
To display different content based on URL parameters in PHP, you can use the $_GET superglobal array to retrieve the parameter values from the URL and then use conditional statements to determine which content to display based on those values.
<?php
// Retrieve the value of the 'page' parameter from the URL
$page = $_GET['page'];
// Use a switch statement to display different content based on the 'page' parameter
switch ($page) {
case 'home':
echo "Welcome to the homepage!";
break;
case 'about':
echo "Learn more about us here.";
break;
case 'contact':
echo "Contact us for more information.";
break;
default:
echo "Page not found.";
}
?>
Related Questions
- What are the benefits of using "\n" versus "<br>" for creating line breaks in PHP-generated text within a textarea?
- What are the advantages of using session_name() in PHP to customize session IDs and improve security?
- How does the use of mod_rewrite impact the visibility of GET parameters in URLs when rewriting them for PHP files?