Looking at previous command-structure examples, you may have noticed frequent use of the header(“Location: …”) tag. Why all the redirecting?

Using the command structure, you often could just set the $command variable to something else, and then the script would go ahead and display the next item or whatever else you need it to do.

But what happens with the user refreshes or presses the back button. If they re-post the same data again, you may be dealing with duplicate data issues, form validation issues, invalid flow concepts, etc.

Using the redirect concepts avoids all of that and the user is safe to press refresh or back or do all the things that users generally do. They won’t be re-posting any form submissions and the URLs they’re provided with will be “safe”. Safe URLs are generally shareable, won’t alter data if someone else clicks on them, and don’t show the user any information that they shouldn’t know about or would be damaging for them to know about.

Redirects keep your code and your user interface clean.

August 28th, 2013

Posted In: Controllers

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: