kwstephenchan Posted April 2, 2006 Share Posted April 2, 2006 Hi evereyone!I got the following simple code. Everytime I pre-run it, it goes directly to the Header function without asking for input (it does if I commented out the Header function), can anyone help and tell me what Have I done wrong, please!Ob_start()<p> </p><form name="form1" method="post" action=""> <p>login (email): <input type="text" name="em"> <input name="pass1" type="password"> <input name="submitf" type="submit"> <input name="resetf" type="reset"> </p></form><p> </p><?php // accept input for user name – in the format of email$uname=$_POST["em"];// determine redirection destination depending on email input by userif ($uname=="123@123.com") $newloc="abc.php"; else $newloc="123.php"; // redirect to new locationheader("location: $newloc");?>ob_end_flush()Thanks and appreciated!! Quote Link to comment https://forums.phpfreaks.com/topic/6376-need-help-on-uncontrollable-header-function/ Share on other sites More sharing options...
Zane Posted April 2, 2006 Share Posted April 2, 2006 the header function has to be used before ANY output to the browserand all this is output[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]<p> </p><form name="form1" method="post" action=""><p>login (email):<input type="text" name="em"><input name="pass1" type="password"><input name="submitf" type="submit"><input name="resetf" type="reset"></p></form><p> </p>[/quote]I'm surprised you're not getting a "Cannot modify header" error Quote Link to comment https://forums.phpfreaks.com/topic/6376-need-help-on-uncontrollable-header-function/#findComment-23060 Share on other sites More sharing options...
kenrbnsn Posted April 2, 2006 Share Posted April 2, 2006 You should only be doing the check and the redirect if the form has been submitted. Change your code to be something like this:[code]<?phpif(!isset($_POST['submitf'])) { ?><form name="form1" method="post" action=""><p>login (email):<input type="text" name="em"><input name="pass1" type="password"><input name="submitf" type="submit"><input name="resetf" type="reset"></p></form><?php}else {// accept input for user name – in the format of email $uname=$_POST["em"];// determine redirection destination depending on email input by user if ($uname=="123@123.com") $newloc="abc.php"; else $newloc="123.php";// redirect to new location header("location: $newloc");}?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/6376-need-help-on-uncontrollable-header-function/#findComment-23076 Share on other sites More sharing options...
kwstephenchan Posted April 2, 2006 Author Share Posted April 2, 2006 [!--quoteo(post=360808:date=Apr 2 2006, 12:21 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 2 2006, 12:21 PM) [snapback]360808[/snapback][/div][div class=\'quotemain\'][!--quotec--]You should only be doing the check and the redirect if the form has been submitted. Change your code to be something like this:[code]<?phpif(!isset($_POST['submitf'])) { ?><form name="form1" method="post" action=""><p>login (email):<input type="text" name="em"><input name="pass1" type="password"><input name="submitf" type="submit"><input name="resetf" type="reset"></p></form><?php}else {// accept input for user name – in the format of email $uname=$_POST["em"];// determine redirection destination depending on email input by user if ($uname=="123@123.com") $newloc="abc.php"; else $newloc="123.php";// redirect to new location header("location: $newloc");}?>[/code]Ken[/quote]Hi Ken and Zanus.Thanks for helping.After I checked for submit status, it works.Zanus, I did not get the modify error message, because I have put in the ob_start() at the very beginning for buffering. I believe this is only available after PHP4.Stephen Quote Link to comment https://forums.phpfreaks.com/topic/6376-need-help-on-uncontrollable-header-function/#findComment-23127 Share on other sites More sharing options...
wildteen88 Posted April 2, 2006 Share Posted April 2, 2006 I would of coded your script the opposite way around like so:[code]<?phpif(isset($_POST['submitf'])) { // accept input for user name – in the format of email $uname=$_POST["em"]; // determine redirection destination depending on email input by user if ($uname=="123@123.com") $newloc="abc.php"; else $newloc="123.php"; // redirect to new location header("location: $newloc");}?><form name="form1" method="post" action=""><p>login (email):<input type="text" name="em"><input name="pass1" type="password"><input name="submitf" type="submit"><input name="resetf" type="reset"></p></form>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6376-need-help-on-uncontrollable-header-function/#findComment-23211 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.