My problem is that I think the header('Locatio n ...') function isn't sending the header immediately and the rest of my script is running before the page redirects.
I am using a $_SESSION array to transfer messages from one page to the next. I want the message available only once, then it should be deleted. I had been using the technique something like this:
Expand|Select|Wrap|Line Numbers
- if (isset($_POST['form_submitted'])) {
- //handle_form
- $_SESSION['message']=$errorMessages;
- header('Location: http://www.thissite.com/new_page.php');
- }
- if (isset($_SESSION['message'])) {
- $showMessage = $_SESSION['message'];
- unset($_SESSION['message']);
- }
- echo $showMessage;
- echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post"><input type="hidden" name="form_submitted" value="v" /></form>
The form is submitted, the page reloads to itself. The form checks everything and records any errors to $errorMessages. It transfers these to the $_SESSION array and it reloads to a new page.
//What seems to happen:
As before... but after the form check, it seems to run the rest of the script, and as the $_SESSION['message'] variable is now set, it goes into the part which unset()s that variable. THEN after this it redirects. Now of course the $_SESSION['message'] is unset and I get no message!
Does this make any sense? It's a bit convoluted. This is a highly simplified version of my page just to illustrate the process. Any help is very much appreciated!
Thanks in advance!!
Henry