Summary of page Jump methods in php Development
The PHP page Jump function is to redirect one webpage to another. For friends who have just learned the PHP language, it is a basic method that must be mastered.
Page Jump may be triggered by clicking links or buttons, or automatically generated by the system. Automatic page Jump is often used in WEB development, and different jump methods can be used as needed, such as delayed jump after prompting operation information, this article summarizes several common page Jump methods in WEB development.
PHP header () function jump
PHP's header () function is very powerful. It also makes simple calls in page url jump. You can use header () to directly jump to the specified url page. In this case, the page Jump is 302 redirection:
?
1 2 3 |
$ Url = "http://www.jb51.net /"; Header ("Location: $ url "); |
We may encounter special jumps. For example, if the website has a page address for 301 redirection, you can configure rewrite on the web, but now I want to tell you, you can use the php header () function to perform 301 redirection. The Code is as follows:
?
1 2 3 |
// Jump to 301 Header ("HTTP/1.1 301 Moved Permanently "); Header ("Location: $ url "); |
Meta settings jump
In the meta information in html, you can directly set the jump, and set the jump delay time and jump url, which are frequently applied. For example, after the payment is complete, the code is very simple to tell the user that the payment is successful and jump to the order page, add the following sentence:
?
1 |
<Meta http-equiv = "refresh" content = "5; url = http://www.jb51.net"> |
The code above indicates that the page automatically jumps to the http://www.jb51.net after 5 seconds.
Javascript jump
Javascript jump is also very simple, just one sentence:
?
1 2 3 |
<Script> Window. location. href = "http://www.jb51.net "; </Script> |
Note: After the above Code is directly redirected, you cannot obtain a referer (also called a source) in the target page address. In the actual project, when a customer asks for a jump to bring the path (that is, the target webpage can get where the page is redirected), we can use javascript to simulate a click, then the jump satisfies the customer's needs.
?
1 2 3 4 5 6 7 8 |
<Script> // There are routes Var aa = document. createElement (""); Aa. setAttribute ("href", "http://www.jb51.net "); Var bodys = document. getElementsByTagName ("body") [0]; Bodys. appendChild (aa ); Aa. click (); </Script> |
Of course, in actual development, we can integrate the following two methods into PHP to facilitate various jump needs.
The above is all the content of this article. I hope you will like it.