If there should be an 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. Implement 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 Network ', LOCK_EX);

If the PHP file runs through a header ("Location: a page URL"), the statement jumps directly to another page, but the jump here does not affect the continuation of the current PHP file. That is to say, after the PHP header jump, the current page of the script will continue to execute. If you need to terminate the script, you need to add exit () or Die ().


But there's no need for some usage.

404 Code

tr>
copy code

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

301

<?
Header ("http/1.1 301 Moved permanently");
Header ("location: www.111cn.net");
?

Related Article

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.