justin7410 Posted April 14, 2013 Share Posted April 14, 2013 Hey there guys, I am trying to create a forgotten password / username file named recover.phpon this page a user will be able to validate his email to see if it exists and if so will send the information to that users registered email in the database. simple enough except i have a confusing issue with having multiple header redirects it seems.MY CODE: <?php ob_start(); include('include/init.php'); logged_in_redirect(); include('include/header.php'); ?> <h1><span>Forgot your username / password ? </span></h1> <p>In just a couple easy steps, we can recover your info and get you back on your way in no time ! <span style="color:#FF0000">( * All Fields are required )</span></p> <? $mode_allowed = array('username','password'); if(isset($_GET['mode']) === true && in_array($_GET['mode'], $mode_allowed) === true) { if(isset($_POST['forgot_email']) === true && empty($_POST['forgot_email']) === false ){ if(email_exists($_POST['forgot_email']) === true) { echo 'ok'; // <----- HERE I WANT TO REPLACE WITH A FUNCTION CALLED RECOVER(); && HEADER(); /* recover($_GET['mode'], $_POST['forgot_email']); header('Location: recover.php?success'); <---- REPLACE "ok" with THIS CODE exit(); */ } else { echo '<p>We could not find this email in our database ! Are you sure you got the right email ?</p>'; } } ?> // FORM BEGINS FOR USER TO SUBMIT THEIR EMAIL FOR VALIDATION <div class="recover_user_info"> <div id="change_password" style="float:left;"> <table style="margin-left:10px; margin-top:10px; margin-bottom:10px;"> <form name="forgot_data" action="" method="post"> <tr> <td class="register_td_left"><span class="">Please enter your email here:</span></td> <td class="register_td_right" colspan="2"><input type="email" name="forgot_email" size="60" maxlength="60" value=""></td> </tr> <tr> <td class="register_td_left"></td> <td class="extra_data" colspan="2"></td> </tr> <tr><td class="register_td_left"></td><td class="extra_data2" colspan="2"><input class="register-button" type="submit" name="forgot_userdata_button" value="Recover my info"></td></tr> </tbody></table></form> </div> </div> <? } else { die('Utter confusion ensues'); //<--- MAIN REDIRECT FROM ISSET CONDITIONAL.. REPLACE die('utter confusion ensues'); WITH header('Location: index.php'); exit(); } ISSUE: when i click submit without any of the header() in place i get an output of "ok" , which is exactly what i want. now when i place the extra code as shown above in the // brackets , the conditional fails and i get the die('utter confusion') when i add just the main header redirect to send a user back to index for not having a the correctly defined "$data_mode" , the code still works. its when i add the second header(), for when the form is being submitted and redirecting to recover.php?success that it wont function correctly. mind you, i have not even inserted the function of recover(); i was commenting it out, just to get the redirect to the success. anytime i click submit with both header() functions declared i get sent back to the index.php or die('utter confusion ensues'); any suggestions as to why this is happening ? i really cant figure out why the conditional passes if no header is the output , yet when the header is present to be outputted , the entire conditional fails. Link to comment https://forums.phpfreaks.com/topic/276924-conditional-passing-but-output-is-being-skipped-and-returns-a-false-result/ Share on other sites More sharing options...
mac_gyver Posted April 14, 2013 Share Posted April 14, 2013 when recover.php redirects using - header('Location: recover.php?success'); it goes to that same page and the only get parameter that is set will be $_GET['success']. the first if() statement is false, it's testing $_GET['mode'], and the code goes to the else part. your code is doing exactly what it is written to do. what do you want to happen? Link to comment https://forums.phpfreaks.com/topic/276924-conditional-passing-but-output-is-being-skipped-and-returns-a-false-result/#findComment-1424640 Share on other sites More sharing options...
justin7410 Posted April 14, 2013 Author Share Posted April 14, 2013 hey mac_gyver, thanks for the reply but, i dont think you understood my problem exactly, or maybe im just not quite getting what your trying to say. when recover.php redirects using - header('Location: recover.php?success'); it goes to that same page and the only get parameter that is set will be $_GET['success']. Yes i am aware of this thats why i am checking to get to that landing page. i was assuming once submitted instead of getting "ok" like i was originally getting , i would now be getting recover.php?success , instead i am being redirected to the homepage, which means my first if is failing. the first if() statement is false, it's testing $_GET['mode'], and the code goes to the else part if the first if() statement is false , then why i am returning "ok" when i submit a correct email ? your post did not seem to address this issue. if the conditional is passing with the correct email ( email is found in db ) , then why is it that as soon as i change the output to redirect using header() the entire conditional becomes false ? that doesnt make sense to me. your code is doing exactly what it is written to do. what do you want to happen? my code is doing exactly what i want it do as long as there is not 2 header() functions declared , yes. but, as i stated as soon as the second header comes into play to send the user to the recover.php?success , no it does not do what i want. i guess thats why i am here asking for suggestions . Link to comment https://forums.phpfreaks.com/topic/276924-conditional-passing-but-output-is-being-skipped-and-returns-a-false-result/#findComment-1424643 Share on other sites More sharing options...
mac_gyver Posted April 14, 2013 Share Posted April 14, 2013 your page is being requested two times. it's not going to index.php directly. the first time it is requested $_GET['mode'] is set and it runs the code you expect it to. the code then redirects to that same page with $_GET['success'] set. that causes it to skip the if() logic and goto the else part where you have a redirect to index.php. Link to comment https://forums.phpfreaks.com/topic/276924-conditional-passing-but-output-is-being-skipped-and-returns-a-false-result/#findComment-1424644 Share on other sites More sharing options...
justin7410 Posted April 14, 2013 Author Share Posted April 14, 2013 Ah i got you, i got it to work , i forgot the step of adding if (isset($_GET['success']) === true && empty($_GET['success']) === true) thanks mac_gyver that was very helpful. Link to comment https://forums.phpfreaks.com/topic/276924-conditional-passing-but-output-is-being-skipped-and-returns-a-false-result/#findComment-1424650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.