Should there be exit after the header function in PHP?

Source: Internet
Author: User


There are usually three kinds:

The code is as follows Copy Code

Location:xxxx:yyyy/zzzz

Content-type:xxxx/yyyy

status:nnn xxxxxx

Common examples

1. Implementation redirection (Status Code 302)

The code is as follows Copy Code

<?php
Header ("Location:http://www.111cn.net");
Exit
?>

Example

The code is as follows Copy Code
<?php
Header ("location:http://www.111cn.net/");
Exit ();
File_put_contents ($_server[' document_root '). Directory_separator. " N.txt ", ' PHP Programmer tutorial Web ', LOCK_EX);

The results show that PHP files run if you encounter a header ("Location: a page URL"), this statement will jump directly to another page, but the jump here does not affect the current PHP file to continue execution. That is, after the PHP header jumps, the script for the current page continues to execute. If you need to terminate the script operation, you need to add exit () or Die ().


But there's no need for some use.

404 Code

The code is as follows Copy Code

<?php
Header (' http/1.1 404 Not Found ');
Header ("status:404 not Found");
?>

301

?
Header ("http/1.1 moved Permanently");
Header ("Location:www.111cn.net");
?>

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.