php displays different pages according to the address
php displays different pages according to the url address. We can pass a The page parameter is implemented. The specific method is as follows:
1. Create a new index.php file and write the code
<?php if (isset($_GET['page']) && $_GET['page']) { $page = $_GET['page']; if (file_exists($_GET['page'] . '.php')) { require ($_GET['page'] . '.php'); }else{ echo "404"; } }else{ echo "home"; } ?>
The above code means to determine whether there is a page parameter. And the page parameter is not empty. Then determine whether the page page file exists. If it exists, import it, otherwise 404 will be output.
2. Create a.php page and b.php page
3. Browser access test:
localhost/index.php?page=a localhost/index.php?page=b
For more PHP related knowledge, please visit PHP Chinese website !
The above is the detailed content of php displays different pages based on address. For more information, please follow other related articles on the PHP Chinese website!