Home  >  Article  >  Backend Development  >  Should there be exit_PHP tutorial after php header?

Should there be exit_PHP tutorial after php header?

WBOY
WBOYOriginal
2016-07-13 10:31:261189browse

Whether I need to write exit after the php header to terminate the program, I never paid much attention to it before. I encountered a bug today and found out that this is still a problem. I wrote a piece of code to test it. The code is as follows:

<?php
header("Location:http://www.phpernote.com/");
//exit();
file_put_contents($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."n.txt",'php程序员教程网',LOCK_EX);

It turns out that if a statement such as header("Location: a page URL"); is encountered during the running of the php file, it will jump directly to another page, but the jump here has no effect. Continue execution of the current php file. That is to say, after the php header jumps, the script of the current page will continue to execute. If you need to terminate the script, you need to add exit() or die().

Articles you may be interested in

  • php get_headers Determine whether the URL is valid
  • php The function and usage of get_headers function
  • php Use header() to download files. The downloaded file prompts that it is damaged and cannot be opened.
  • php simulates the get_headers function
  • php header 404 jump error page
  • Summary of usage of php header
  • The usage and difference of using break, continue, goto, return, exit to break out of multiple loops in PHP
  • php finds whether a certain value exists in the array (in_array() ,array_search(),array_key_exists())

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764074.htmlTechArticleWhether it is necessary to write exit after the php header to terminate the program. I never paid much attention to it before. I encountered a bug today. I found that this is still a problem, so I wrote a piece of code to test it. The code is as follows...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn