;" and so on."/> ;" and so on.">
Home > Article > Backend Development > What is the php automatic jump code?
##The operating environment of this tutorial: windows7 system, PHP7 .1 version, DELL G3 computerphp automatic jump code: 1. Use header function to implement jump, code syntax such as "header("location:...");"; 2. Use meta to implement jump, code such as "< ;meta http-equiv="refresh";url=...">;" and so on.
Commonly used web page jump codes in PHP
1. Use the header() function
Enter the following code at the beginning of the php page:<?php header("location:http://www.php.cn"); ?>Then, we name it 1.php. When 1.php is accessed, it will automatically jump to www. php.cn page, what needs to be emphasized here is that to use this method, this line of code must be written at the front. If you don’t want to write it at the front, I will provide another method later.
2. Use meta to achieve jump
Enter the following code at the head of the php page or html page:<meta http-equiv="refresh" content="5;url=http://www.php.cn">;Then, we will name the page 2.php or 3.htm. When accessing 2.php or 3.htm, it will automatically jump to the page www.php.cn. Note that the number 5 in the content means how long it will take before the jump starts. This is set here It is 5, which means that it will take 5 seconds for the page to jump to the target page. It is recommended that you set the jump time not to exceed 10 seconds.
3. Use javascript to implement the jump.
Enter the following code in the php page:<?php header('content-type:text/html;charset=utf-8'); $url='index.php'; //立即跳转至目标页面 echo <script>window.location.href='$url';</script>; ?>Then, we name the page 4.php. When 4.php is accessed, it will automatically jump to www .baidu.com page. It should be noted here that the JavaScript script itself is not written in this way. Since it is used in PHP, certain modifications have been made. You can also directly create a .js file and enter the following code, Then just reference the file later:
<script language="javascript"> document.location="index.php"; </script>Let’s name it 5.js first to facilitate my use when summarizing later.
Various jump methods Summary of mixed use
Create a new php page and enter the following code in it:<?php $a=1; if($a==1) include "1.php"; if($a==2) include "2.php"; if($a==3) include "3.htm"; if($a==4) echo "<script language=\"javascript\">"; echo "document.location=\"http://www.baidu.com\""; echo "</script>"; if($a==5) include "5.js"; ?>Save the file and name it index.php. The first method is to access index.php Jump in, and then continue to modify $a=1 to 2, 3, 4, 5, then you can achieve jumps in the various methods mentioned above. Finally, briefly mention that in the above mentioned Among several methods, only the method of "using meta to implement jump" mentions the setting of jump time. So how to set the jump time in other methods? You can use the sleep() function. The specific usage method is as follows Not much to say, you can find relevant information online. Recommended learning: "
PHP Video Tutorial"
The above is the detailed content of What is the php automatic jump code?. For more information, please follow other related articles on the PHP Chinese website!