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 ())