Summary of page jump method in PHP development

Source: Internet
Author: User
Tags php language

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

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

PHP header () function jump

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

?
12 $url= "http://www.jb51.net/"header( "Location: $url");

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

?
123 //301跳转 header( "HTTP/1.1 301 Moved Permanently");   header( "Location: $url");

Meta settings jump

The meta information in HTML can be set directly to jump, you can set the jump delay time and jump URL, often applied, such as payment is finished to tell the user to pay the success and jump to the order page, the code is very simple, 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 direct sentence:

?
123 <script> window.location.href="http://www.jb51.net"; </script>

Note that the above code directly after the jump, in the destination page address is not get the route (Referer, also known as source), in the actual project, encountered a customer request jump to bring the road (that is, the target page can get to the page from where to jump), at this time, We can simulate a click with JavaScript and then jump to meet the customer's needs.

?
12345678 <script> //有来路 varaa = document.createElement("a"); aa.setAttribute("href","http://www.jb51.net"); varbodys=document.getElementsByTagName("body")[0]; bodys.appendChild(aa); aa.click(); </script>

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

Summary of page jump methods in PHP development

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.