if ( $FormIsSent == "My-String ) { process form header( "Location: url" ); } else { display form <input type = "hidden" name = "FormIsSent" value = "My-String"> }
I use this technique on my sites all the time. The only restriction is you can't have any output before the header. If there is an error in the form, store it in an error variable: $error[NameForError] = "Problem with form"; then use a foreach to get the values back out if ( count( $error ) ) { foreach ( $error as $key=>$value ) { print "Error with $key - $value<br>"; } } else { header( "location: http://youurl.com/formsuccess.php" ); exit; } ----- Original Message ----- From: "Max Graham" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, November 28, 2002 5:50 AM Subject: Re: [PHP-WIN] Redirect browser to another URL? > You know, this is exactly what happened to me. I was trying to design a > comments page for a weblog to open in a popup. The page had a submission > form that would submit back to itself. 'course, I was banging my head on the > wall trying to come up with a way to get the page to detect whether it had > received a form submission and write the comments to a comment file, and > then include the comment file with the form afterwards. I kept coming up > with the results of fopen(), fputs(), fflush(), and fclose() coming back as > false, which equals failed. I eventually did go to a separate page to do the > file writing, and that page finishes up with a 1-second delay using the > javascript setTimeout() for this command in a standalone function: > > echo "location.replace('blogcomments.php?target=".$target."');\n"; > > Inelegant, but it works. I haven't had too much experience with the header > function, and knowing how long it took me to bang this one out, I might set > something on fire trying it :) > > Anyone else had any fun with this issue? > > Message-ID: <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > Reply-To: "Jack Kelly Dobson" <[EMAIL PROTECTED]> > From: "Jack Kelly Dobson" <[EMAIL PROTECTED]> > Date: Wed, 27 Nov 2002 10:19:30 -0600 > Subject: Re: [PHP-WIN] Redirect browser to another URL? > > Thanks for all the help guys. > > My problem, as most of you figured, is that my script has a form in it that > re-runs itself when the form is submitted so there is only one script > including the form and all the validation for the form. If the validation is > successful it sends you to a different page depending on the information > posted in the form. There was therefore no way I could get the header() to > be at the top of the returned data. > > I ended up using: > > if ($condition) { > print("<SCRIPT LANGUAGE='JavaScript'>window.location='" . $url . > "'</SCRIPT>"); > } > > A rather elegant solution I've decided. > > Oh, and FYI to all you IIS users out there... (At least I'm assuming it's > IIS and not the Windows platform itself. I'd be interested to know what > Windows users running Apache are experiencing). > > I didn't have this problem with my script until I migrated it to a > Linux/Apache platform. > > I assume that means that when I was doing it the original way that I had > multiple sets of header information and no telling what else being sent back > to the browser and IIS wasn't producing any error. Anyone using IIS and the > header(location: '') function might want to make sure they aren't exposing > data they didn't mean to. > > j- > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php