Categories
Posts

PHP Helpers: redirect_url

New function: redirect_url

[sourcecode lang=”php”]
if ( !function_exists( ‘redirect_url’ ) ) {
function redirect_url( $url, $status = 302 ) {
header( "Location: {$url}", TRUE, $status );
exit;
}
}
[/sourcecode]

A special case wrapper around the header function to do URL redirection. I specifically added the exit call inside the function so that redirect happens immediately. That way I don’t have a chance to forget about it later on 🙂