How to Implement Automatic Webpage redirect: PHP, JSP (bottom)

Source: Internet
Author: User

This article discusses several implementation methods for Automatic Webpage redirect.
Method 1: Using meta tag is one of the indispensable tags in HTML. It provides the meta information of documents. Its parameters include:
① http-equiv: http File Header related to the data in the document
② content: data related to the name HTTP header
③ name: Document Description
④ URL: URL associated with metadata when we define the attribute http-equiv as refresh, the system will jump to the corresponding page within a certain period of time according to the value specified by content when opening this web page, content = "seconds; url = URL "is defined to jump to the specified URL for too long. The following meta tag tells the system that the page automatically jumps to the dark horse online power after one second:

the above Code needs to be added to the HTTP document header, between and . Generally, the meta tag is followed by . If you need multiple meta tags, each of them can take up one row.
This method is applicable to any environment, including static website space.
Method 2: Use the header function. The header function is one of the HTTP-related functions in PHP built-in functions. This function sends the HTTP header to the browser. You can use it to redirect the URL, that is, to redirect the page to another specified webpage. The following example automatically opens the dark horse online power homepage after execution:
header ("Location: http://www.jb51.net/");
note, the header function can only be used before the tag in the page code, that is, before the HTTP header has no other header () sent to the browser, and, the previous page cannot print or echo any content. In other words, before appears on the page, Program only processes header events. Despite such strict requirements, you can use it flexibly to achieve the automatic page Jump function. For example, you can log on to the page and determine where the page jumps by judging whether the data submitted by the user is legal. The following is a simple example:

Copy code The Code is as follows: <? PHP
/* Login program-File Name: Login. php
Program function-determine the user logon password */
If ($ _ post ['submit ']) {
Session_start ();
If ($ _ post ['pws '] = '000000') {// if the password is 123
$ _ Session ['passwd'] = '000000'; // write session data
Header ("Location: index. php"); // jump to the normal page
} Else {
Header ("Location: Login. php"); // jump to the logon page
}
}
// The form code is omitted (you can also use pure HTML code to write a form. If so, the code should be placed after the program
?>
<? PHP
/* Check session data-file name: index. php
Program function-checks whether the password in the session data is 123. If not, the system returns
Logon page */
Session_start ();
If ($ _ session ['passwd']! = '20140901') header ("Location: Login. php ");
// Other code (the pure HTML code should be written after the program)
?>

This method can only be used in a space environment that supports PHP.
Method 3: javascriptjs is very flexible and can be used to create powerful program scripts. Here is only a simple JS example of automatic page Jump. After the following code is executed, the browser will automatically go to The website. This code can be placed in any valid location on the page:
<Script language = "JavaScript" type = "text/JavaScript"> window. Location. href ("http://www.jb51.net"); </SCRIPT> This Code applies to any Web environment. If you add a timer, it will be even more amazing.

frequent page Jump problems, for example, when some websites need to log out, a prompt page appears.
what are you saying that you are exiting only class-Objective phone calls, some also need to make a countdown
Method 1:

Method 2:
This is a JS application.
test code: copy Code the code is as follows:

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.