Three ways to jump to a PHP page

Source: Internet
Author: User
Tags php code

In a web system, jumping from one Web page to another is one of the most common technologies in the project.

Page jumps may be caused by a user clicking on a link, a button, or a system is automatically generated.

Here is a common way to realize the automatic page jump in PHP.

PHP page Jump One, header () function

The header () function is a very simple way to make a page jump in PHP.
The main function of the header () function is to output HTTP protocol headers (headers) to the browser.
The header () function is defined as follows:

void header (String string [, bool replace [, int http_response_code]])

Optional parameter replace indicates whether to replace the previous similar header or to add a header of the same type, which defaults to replace.

The Second optional parameter Http_response_code forces the HTTP corresponding code to the specified value.
The header of the location type in the header function is a special header invocation that is commonly used to implement page jumps.
Attention:

1.location and ":" No space between, otherwise will not jump.
2. You cannot have any output before using the header.
The PHP code after 3.header will also be executed.


< PHP
redirect Browser
Header ("location:http://www.111cn.net/");
Ensure that subsequent code is not executed after redirection
Exit
?>

PHP page jump two, meta tags

Meta tag is the HTML in charge of providing the document Meta Information label, in the PHP program to use the tag, you can also implement page jump.
If you define HTTP-EQUIV as refresh, the page will be opened to the corresponding page within a certain amount of time according to the value specified by the content.
If set content= "seconds; url= url", then define how long after the page jumps to the designated URL.


< meta http-equiv= "Refresh"
Content= "1;url=http://www.111cn.net/" >
< PHP
$url = "http://www.111cn.net/";?>
< html>
< head>
< meta http-equiv= "Refresh" content= "1;
url=<, PHP echo $url?> ">
< body>
The page stays only one second ...
</body>

PHP page jump three, JavaScript

For example, this code can be placed in any legal position in the program.


<?php 
$url = "http://www.111cn.net/"; 
Echo < script language= ' JavaScript '
Type= ' Text/javascript ' > '; 
Echo ' window.location.href= ' $url '; 
Echo ' </script> '; 
?
above is we introduce to you three kinds of PHP page jump implementation method.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.