Home  >  Article  >  Backend Development  >  php displays different pages based on address

php displays different pages based on address

angryTom
angryTomOriginal
2019-11-20 16:36:322715browse

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";
}
?>

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

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!

Statement:
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