Home > Article > Backend Development > How to jump to the page after a few seconds in php
How to jump to the page after a few seconds in php: 1. Use the Header function to jump; 2. Use HTML inherent tags to jump; 3. Output javascript and use Js code to automatically jump to the php page The purpose of transfer.
Recommendation: "PHP Video Tutorial"
Php itself does not have a complete page jump function. Maybe the Header function counts as one, but it can only be used for the first line of the page. If placed at the end of the Php page, unless the previous Php does not output any characters, an error will be reported. The following are three methods of automatic page jump in Php:
1: Use the Header function.
2: Use HTML inherent tags. (Not only applicable to Php, but also applicable to ASP, .Net, and Jsp).
Three: Output javascript and use Js code to achieve the purpose of automatic jump to the Php page. (It also applies to languages other than Php, but the corresponding language codes are different). 1. Use HTTP header information (Header function)
That is, use PHP’s HEADER function. The function of the HEADER function in PHP is to issue control instructions to the browser that should be passed through the WEB server specified by the HTTP protocol, such as declaring the type of return information ("Context-type: xxxx/xxxx"), the attributes of the page ("No cache", "Expire"), etc.
The method to use HTTP header information to automatically jump to another page in Php is as follows:
<?php $url = index.php Header("HTTP/1.1 303 See Other"); Header("Location: $url"); exit; ?>
Note that there is a space after "Localtion:". 2. Use HTML tags (REFRESH attribute in META)
Use HTML tags, that is, use META’s REFRESH tag. For example:
<?php $url = index.php;?> <HTML> <HEAD> <META HTTP-EQUIV="REFRESH" CONTENT="10; URL=<? echo $url;?>> </HEAD> <BODY> </BODY> </HTML>
Note: CONTENT="10 here means Said to jump after 10 seconds. 3. Use javascript script to implement
Examples are as follows:
<?php $url=index.php; echo "<!--<SCRIPT LANGUAGE="javascript">"; echo "location.href='$url'"; echo "</SCRIPT>-->"; ?>
-------------------- -------------------------------------------------- ----------------------------------------
<? //PHP自带函数 Header("Location: http://www.php.com "); ?> <? //利用meta echo "<meta http-equiv='refresh' content='0; url=http://www.php.com'>"; ?>
-- -------------------------------------------------- -------------------------------------------------- ---------
<? //利用Javascript语言 echo "<script language='javascript'>"; echo " location='http://www.php.com' ; "; echo "</script>"; ?>
---------------------------------- -------------------------------------------------- --------------------------
Note: When using the Header function, the web page must not produce any output, especially at this time Pay attention to the space problem. That is, it must be placed at the beginning of the web page
The above is the detailed content of How to jump to the page after a few seconds in php. For more information, please follow other related articles on the PHP Chinese website!