Summary of page jump method in PHP development

Source: Internet
Author: User

The function of PHP page jump is to jump one page to another page in the website. For a friend who has just learned the language of PHP, it is the basic method that must be mastered.

Page jumps may be triggered by a user clicking on a link, a button, or a system that is automatically generated. Page automatic jump in the Web development is often used, and according to the requirements can be different jump mode, such as the prompt operation of information after the delay jump, this article summarizes the Web development of several common page jump methods.

PHP header () function jump

PHP's header () function is very powerful, where the page URL jump is also called simple, using header () directly jump to the specified URL page, when the page jump is 302 redirect:

?

1 2 3 $url = "http://www.jb51.net/"; Header ("Location: $url");

We may encounter a special jump, such as a website version of a page address to do 301 Redirect, of course, you can through the Web configuration rewrite to achieve, but now I want to tell you, you can use PHP header () function do 301 jump, the code is as follows:

?

1 2 3 301 Jump Header ("http/1.1 moved Permanently"); Header ("Location: $url");

Meta settings jump

Meta information in HTML can be set directly to jump, you can set the jump delay time and jump URL, often applied, such as paid to tell the user to pay success and jump to the order page, the code is very simple, add a sentence in:

?

1 <meta http-equiv= "Refresh" content= "5;url=http://www.jb51.net" >

The above code indicates that the page will automatically jump to http://www.jb51.net after 5 seconds.

JavaScript jump

JavaScript jump is also very simple, a straight word:

?

1 2 3 <script> window.location.href= "Http://www.jb51.net"; </script>

Note that the above code directly after the jump, in the target page address is not access to the routing (Referer, also known as the source), in the actual project, encountered a customer requirements jump to bring the road (that is, the target page can get to the page from where the jump from), at this time, We can use JavaScript to simulate a click, and then jump to meet the needs of customers.

?

1 2 3 4 5 6 7 8 <script>//have antecedents of var AA = document.createelement ("a"); Aa.setattribute ("href", "http://www.jb51.net"); var bodys=document.getelementsbytagname ("Body") [0]; Bodys.appendchild (AA); Aa.click (); </script>

Of course, the actual development of the following two ways we can integrate into PHP, easy to apply a variety of jump needs.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.