Over a million developers have joined DZone.

PHP Redirect Function

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

After form submission or a page redirect is triggered, it's commonplace to redirect the user to a different page or to the same page, formatted in a different way. Usually, you'd complete this by coding:

header('Location:  destination.php');

This is a completely acceptable way to code your pages, but I prefer to use a redirect function instead. Why? It's much more readable, and quite honestly, I'm tired of writing the header('Location: …') code.

function redirect($url,$permanent = false)
header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$url);

Do you have any suggestions for improvement?

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.


Published at DZone with permission of David Walsh. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}