Back to Browse

How to fix the "headers already sent" error: omit the closing tag in pure PHP scripts

40.1K views
Apr 20, 2018
3:59

Full PHP course: ➤ https://davehollingworth.com/courses/ It's best practice to omit the PHP closing tag for files that just contain PHP. This is because it's too easy to insert whitespace after the closing tag. If you're using a function like header, session_start or setcookie, which send HTTP headers, no whitespace can be sent before the headers. If it is, you get the "headers already sent" error. Resources shown in the video: http://php.net/manual/en/language.basic-syntax.phptags.php https://www.php-fig.org/psr/psr-2/ http://php.net/manual/en/outcontrol.configuration.php#ini.output-buffering

Download

0 formats

No download links available.

How to fix the "headers already sent" error: omit the closing tag in pure PHP scripts | NatokHD