Thursday, December 4, 2008

PHP Header Redirect

Most people may already know this but for some reason I always forget the syntax (I know... its simple...).  So here is how you can redirect to a page with PHP.

Remember: You have to redirect BEFORE loading any HTML tags or header information.  This should always be tested before ANY echo/print tags or any output.

header('Location: http://www.example.com/');
exit;

Don't forget the exit, this prevents the rest of the page from loading and possibly stopping your redirect.

No comments: