PHP Program Header Location Jump considerations

Source: Internet
Author: User
As we all know, PHP website jumps three ways: JS, HTML META Refresh, PHP header ("Location: $url"). But here is a very small detail that can easily lead to errors.

Header ("Location:test. PHP ") Jump success in addition to note the following three points there is a prerequisite must be noted:

1, location and ":" No space between, otherwise it will be wrong.
2, before using the header can not have any output.
3. The PHP code after the header will also be executed.

The premise is that your editor is written in UTF-8 without BOM format, not in UTF-8 format. Remember!

Once made a jump program, the results ignored this point, resulting in the jump is actually not successful.

Program all source code as follows, program address: http://www.***.com/go.php

<?phperror_reporting (7); $url = UrlDecode (Trim ($_request[' url ")), if ($url) {    header (" Location: $url ");} else {    exit (' Error input,<a href= ' http://www.***.com/?f=go.php ' >go back</a> ');}


When the access address is: http://www.***.com/go.php?url=http%3a%2f%2fwww.zbphp.com%2f, the Firefox browser is normal. Later this jump program copied to the company's other website, so that some friends on the QQ test, the result many people say that cannot open: IE kernel browser direct prompt cannot access or find, chrome sometimes prompts to be reset or cannot find, use the Firefox test also even occasionally hint can't find, But it only shows up once more.

Check the code carefully, there is no problem. Moreover, Firefox can jump, after thinking of the previous reading is: IE browser if the output bytes are too small (less than 512 bytes), then the

<?phperror_reporting (7); function Gheader ($url) {echo ' 

For PHP jumps, I think the best way is to use js+html META . HTML Meta can ensure that a visitor can jump to the same condition if JS is disabled .

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.