How can PHP be used to switch between different pages using parameters like ID?
To switch between different pages using parameters like ID in PHP, you can create a script that checks the value of the ID parameter in the URL and includes the corresponding page based on that value. This can be achieved by using a switch statement or an if-else condition to handle different cases.
<?php
$id = $_GET['id']; // Get the ID parameter from the URL
switch ($id) {
case 1:
include 'page1.php';
break;
case 2:
include 'page2.php';
break;
case 3:
include 'page3.php';
break;
default:
include 'error.php'; // Include an error page for invalid IDs
}
?>
Keywords
Related Questions
- What are the potential issues when upgrading from PHP4 to PHP5 on older operating systems like Windows 95?
- Are there any potential security risks associated with the session.auto_start setting in PHP?
- How can the automatic redirection after 3 seconds in a PHP script be improved to prevent re-execution of the login script?