Php page jump to another page various jump page code

Source: Internet
Author: User
Tags php code net domain

Php header () page jump

I migrate the blog from http: // www. Your domain name/blog to the http://www.111cn.net domain name, when the user visits the previous blog address, automatically jump to the corresponding article of the current blog

The code is as follows: Copy code

$ Url_this = strtolower ('http: // '. $ _ SERVER ["SERVER_NAME"]. $ _ SERVER ["REQUEST_URI"]);
$ Go_url = str_replace ('http: // www. Your domain name/blog ', 'http: // www.111cn.net', $ url_this );
Header ("location: $ go_url"); exit;


The header () function is defined as follows:

Void header (string [, bool replace [, int http_response_code])
The optional parameter replace indicates whether to replace the previous header or add a header of the same type. The default parameter is replace.
The second optional parameter http_response_code sets the HTTP code as the specified value. The Location header in the header function is a special header call, which is often used to redirect pages.

Note:

1. No space is allowed between location and:; otherwise, no jump is made.
2. There cannot be any output before using the header.
3. The PHP code after the header will also be executed.

There is also a js + php page jump method

JavaScript (common and recommended)

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

The code is as follows: Copy code

<? Php
$ Url = "http://www.111cn.net ";
Echo "<script language = 'javascript 'type = 'text/javascript '> ";
Echo "window. location. href = '$ url '";
Echo "</script> ";
?>

1. Page jump code in HTML code

HTML meta refresh and redirect page
Refresh property value-refresh and redirect page
* Refresh is used to refresh and redirect pages.
* Refresh appears in the http-equiv attribute. The content attribute is used to indicate the start time of refresh or redirect and the URL to jump.

Meta refresh example

Refresh the page 5 seconds later:

The code is as follows: Copy code

<Meta http-equiv = "refresh" content = "5"/>

Go to the mengzhidu homepage in 5 seconds:

The code is as follows: Copy code

<Meta http-equiv = "refresh" content = "5; url = http://www.111cn.net"/>

Click submit to jump

Click <input type = "submit" name = "submit" value = "OK"/>

Use the POST method <form action = "X. php" method = "post">

X. php page only after the judgment logic is processed

The code is as follows: Copy code

<? Php
// Isset function
If (isset ($ _ POST ["name"])
{
Header ("Location: XX. php? Name = ". $ _ POST [" name "]);
 }
?>

Note that the current page has output content, so an error will be reported in PHP during this jump.

The above page jump code can be used to jump between your page and the page, and some can also achieve page jump in other environments.

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.