How can PHP be used to dynamically switch between different files based on user input?
To dynamically switch between different files based on user input in PHP, you can use a combination of conditional statements and include or require functions. By capturing the user input, you can determine which file to include or require in your PHP script.
<?php
$user_input = $_GET['page']; // Assuming user input is passed through the 'page' parameter in the URL
switch ($user_input) {
case 'home':
require 'home.php';
break;
case 'about':
require 'about.php';
break;
case 'contact':
require 'contact.php';
break;
default:
require 'error.php'; // If user input does not match any case
}
?>
Keywords
Related Questions
- How can the DateTime extension in PHP be utilized to efficiently count the number of specific weekdays within a given time interval?
- Are there any other methods or techniques to restrict access to scripts run via Cron jobs in PHP, apart from those mentioned in the forum thread?
- What steps should be taken to troubleshoot and resolve issues related to fetching data from a database using mysqli in PHP?