How can PHP scripts efficiently manage multiple pages of dynamic content without creating separate pages for each question?
To efficiently manage multiple pages of dynamic content without creating separate pages for each question, PHP scripts can utilize URL parameters to determine which content to display on a single page. By passing parameters through the URL, the PHP script can dynamically generate the appropriate content based on the parameters provided.
<?php
// Check if a parameter is set in the URL
if(isset($_GET['page'])) {
$page = $_GET['page'];
// Use a switch statement to determine which content to display based on the parameter
switch($page) {
case 'about':
echo 'This is the About page.';
break;
case 'contact':
echo 'This is the Contact page.';
break;
default:
echo 'Page not found.';
break;
}
} else {
echo 'Welcome to the homepage.';
}
?>