Home > Backend Development > PHP Problem > php displays different pages based on address

php displays different pages based on address

angryTom
Release: 2023-02-28 15:56:02
Original
2775 people have browsed it

php displays different pages based on address

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[&#39;page&#39;]) && $_GET[&#39;page&#39;]) {
	$page = $_GET[&#39;page&#39;];
	if (file_exists($_GET[&#39;page&#39;] . &#39;.php&#39;)) {
		require ($_GET[&#39;page&#39;] . &#39;.php&#39;);
	}else{
		echo "404";
	}
}else{
	echo "home";
}
?>
Copy after login

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
Copy after login

php displays different pages based on address

php displays different pages based on address

php displays different pages based on address

php displays different pages based on address

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template