Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of using PHP header for page jump

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail for you how to solve the problem of using PHP header to jump to the page, the content of the article is of high quality, so the editor shares it for you to do a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

When we do a page jump, we usually use PHP header. So how to use PHP header correctly? What problems should we pay attention to in the process of using it?

Using header ("location:test.php") to jump in PHP should pay attention to the following points, which are helpful to solve some problems often encountered by beginners.

1. There must be no space between location and ":", or there will be an error.

2. You can't have any output before using header.

3. The PHP code after header will also be executed.

The following is a comparison with the redirected response.redirect in asp:

Example 1:

Response.redirect ".. / test.asp"

Header ("location:../test.php")

The difference between the two:

The redirect function of asp works after the header file is sent to the customer.

Such as

< html>

< head>

< /head>

< body>

< %response.redirect "../test.asp"%>

< /body>

< /html>

Check that the following code in php will report an error:

< html>

< head>

< /head>

< body>

< /body>

< /html>

It can only be like this:

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

< html>

< head>

< /head>

< body>

...

< /body>

< /html>

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

Example 2:

In asp

< html>

< head>

< /head>

< body>

< /body>

< /html>

The result is to redirect the a.asp file. Where's php?

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

< html>

< head>

< /head>

< body>

< /body>

< /html>

We found that it redirected b.php.

It turns out that the following code will not be executed after redirect is executed in asp.

After executing header, php continues to execute the following code.

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

Normally, we use

If (...) Header ("..."); else {...}

But we can simply use the following PHP header method:

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

Also note that if you are using Unicode (UTF-8) encoding, there will be problems, you need to adjust the PHP header cache settings.

< [email=%@]%@LANGUAGE="VBSCRIPT[/email]" CODEPAGE="936"%>

< %if Request.ServerVariables("SERVER_NAME")="s.jb51.net" then response.redirect "news/index.htm" else%>

< %end if%>

< script>

Var url = location.href; if (url.indexOf ('http://www.jb51.net/')!=-1)location.href='/index/index.htm'; if (url.indexOf (' http://www.kanshule.com/')!=-1)location.href='/index1/index.htm'; if (url.indexOf ('http://www.shouji17.com/')!=-1)location.href='/cn/index.asp';)) If (url.indexOf ('http://www.baidu.com/')!=-1)location.href='/cn/index.asp';)

< /script>

On how to solve the problem of how to use PHP header page jump to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report