Write PHP scripts without ?>
It is good practice that all PHP files should have only one opening <?php and the rest of the file is defined to be only PHP. If you need to render HTML, put that into another file and use your PHP script to render that HTML file instead.
This reduces problems such as ghost whitespaces causing "Output already written before header" errors.
Written by Sam-Mauris Yong
Related protips
2 Responses
I knew it was a good practice but I didn't know why. Thanks for sharing.
It also keeps your functionality clean from the presentation... Much like how one should NEVER write inline CSS, always keep your styling out of your HTML. For the love of god.
I opened an ASP file today that had all the HTML in the top, then all the jquery in the last 1000 lines. Inline CSS ever'where... I had to open it because the developer couldnt figure out why she was getting errors... blink
Have a fresh tip? Share with Coderwall community!
PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.
Security insights from Cside