PHP & MySQL | Tutorials

David Carr

Avoiding: Headers already sent or Cannot modify header information

From time to time you may want to refresh the page or redirect the page with php this is very easy to do using the php header command, To use a header it has to be used before any output has started on the page. In other words it has to come before anything is printed including the docytype.

This is less then ideal, thankfully there is a way to use the header function after output has starting by turning on output buffering this enabled you to call a header function anywhere on the page, the syntax to use is very simply at the very top of the file open php then then type ob_start() this turns out output buffering:

<?php ob_start(); ?>

Now you can call a header function anywhere within your page. To make sure you clear resources that are not being used at the very bottom of your file flash the buffer bu typing ob_flush() inside php:

<?php ob_flush(); ?>

This is a very simple but powerful solution.

Domains are often purchased from multiple providers, keeping track of where a domain is and its DNS settings can be tricky. Domain Mapper solves this by listing all your domains in one place. View your DNS settings and receive reminders to renew your domains. Try it today.

Support my work by donating with PayPal.

Subscribe to my newsletter

Subscribe and get my books and product announcements.

© 2009 - 2021 DC Blog. All code MIT license. All rights reserved.