How to jump to the page after a few seconds in php

藏色散人
Release: 2023-03-04 19:48:01
Original
4040 people have browsed it

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.

How to jump to the page after a few seconds in php

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

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

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=&#39;$url&#39;";
echo "</SCRIPT>-->";
?>
Copy after login

-------------------- -------------------------------------------------- ----------------------------------------

<?
//PHP自带函数
Header("Location: http://www.php.com ");
?>
<?
//利用meta
echo "<meta http-equiv=&#39;refresh&#39; content=&#39;0; url=http://www.php.com&#39;>";
?>
Copy after login

-- -------------------------------------------------- -------------------------------------------------- ---------

<?
//利用Javascript语言
echo "<script language=&#39;javascript&#39;>";
echo " location=&#39;http://www.php.com&#39; ; ";
echo "</script>";
?>
Copy after login

---------------------------------- -------------------------------------------------- --------------------------

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!

Related labels:
php
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