Php header should have exit?

Source: Internet
Author: User

After the php header, do you need to write exit to terminate the program? I didn't care too much about it before. Today I encountered a bug and found this problem. I wrote a code segment to test it, the Code is as follows:

<? Phpheader ("Location: http://www.phpernote.com/"); // exit (); file_put_contents ($ _ SERVER ['document _ root']. DIRECTORY_SEPARATOR. "n.txt", 'php programmer tutorial net', LOCK_EX );

It turns out that if the PHP file encounters a header ("Location: a page URL") during running, it will jump directly to another page, however, the redirection does not affect the execution of the current PHP file. That is to say, after the php header jump, the script on the current page will continue to be executed. To terminate the script, add exit () or die ().

Articles you may be interested in
  • Php get_headers determines whether the URL is valid
  • Functions and usage of the php get_headers Function
  • Php uses header () to download files. The downloaded files prompt that they are damaged and cannot be opened.
  • Simulate the get_headers function in php.
  • Php header 404 jump to the error page
  • Php header usage Summary
  • Use break, continue, goto, return, and exit in multiple loops in PHP
  • Php searches for the existence of a value in the array (in_array (), array_search (), array_key_exists ())

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.