I make use of PHP’s handy header function to handle simple page redirects for me, perhaps a bit of a cheap way of doing it, but one that is remarkable effective. Sure, you need to change the way you code a little and perhaps introduce some ob_start and ob_end_flush calls if necessary, but on the whole a good old header(‘Location: newpage.htm’) call works pretty damn well.
But here’s a handy note, something to keep in mind when redirecting to a new page using the header function.
Sometimes, somehow, somewhere, a browser script might/will/does continue silently running even after you called your header relocate function, introducing some potentially hazardous side affects because some or other critical session variables or something or other have been set to something they simply weren’t meant to be.
Often this is noticeable with login processing backend scripts, where logins will mysteriously work or fail depending on your set up, occurring purely because session variables have been set when you didn’t think they would be because according to you, the page had already redirected.
So a simple solution to this?
Well the reliable little die() statement works pretty damn well in this case. So the resulting code?
header('Location: newpage.htm'); die();
A simple tip, but one worth remembering.
Related Link: http://php.net/manual/en/function.header.php
You might also enjoy:
-
While caching makes every Internet user's life so much better, there are of course times when it can be an absolute bane as well - especially when you are m ...
-
Now as I've mentioned numerous times before, my main blog at https://codeunit.co.za runs of a file-based, heavily modified version of Simple PHP Blog, si ...
-
Saving a web page to a PDF file for later offline viewing has just become a whole lot simpler thanks to the excellent pdfmyurl.com web service that aims ...
-
The jQuery UI library brings with it a host of cool effects and elements to apply to your project, one of which is the pretty cool accordion effect that bas ...
-
With PHP's built in access to the decent GD graphics library, generating a thumbnail image from a larger photo turns out to be pretty simple to achieve. Bel ...