PHP Header for page Jump considerations, header jump

Source: Internet
Author: User

PHP Header for page Jump considerations, header jump

Preface

This article describes how to useheader("location:test.php")Pay attention to the following points for redirection, which helps solve some problems that beginners often encounter.

1. There must be no space between location and:. Otherwise, an error will occur.

2. There cannot be any output before using the header.

3. the PHP code after the header is executed.

Below is the redirection with aspresponse.redirectComparison:

Example 1:

response.redirect "../test.asp"header("location:../test.php");

Differences:

AspredirectThe function can take effect after the header file is sent to the customer.

For example

The following code in php reports an error:

You can only do this:

<?header("location:../test.php");?>

That is, the header function cannot send any data to the customer.

Example 2:

Asp

The result is to redirect the. asp file.

What about php?

<?header("location:../a.php");header("location:../b.php");?>

We found that it redirects B. php.

It turns out that after redirect is executed in asp, subsequent code will not be executed.

Php continues to execute the following code after executing the header.

In this regard, the header redirection in php is not as good as the redirection in asp. Sometimes, after we want to redirect, we cannot execute the following code:

Generally, we use

if(...)header("...");else{...}

However, we can simply use the following method:

if(...){ header("...");exit();}

Note that if you useUnicode(UTF-8)Encoding may also cause problems. You need to adjust the cache settings.

<[email=%@]%@LANGUAGE="VBSCRIPT[/email]" CODEPAGE="936"%><%if Request.ServerVariables("SERVER_NAME")="s.jb51.net" thenresponse.redirect "news/index.htm"else%><%end if%><script>var url = location.href;if(url.indexOf('http://www.devdao.com/')!=-1)location.href='/index/index.htm';if(url.indexOf('http://www.knowsky.com/')!=-1)location.href='/index1/index.htm';if(url.indexOf('http://www.google.com/')!=-1)location.href='/cn/index.asp';if(url.indexOf('http://www.baidu.com/')!=-1)location.href='/cn/index.asp';</script>

Summary

The above is all about this article. I hope to help you in your study or work. If you have any questions, please leave a message.

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.