Schlo_50 Posted June 30, 2008 Share Posted June 30, 2008 Hi guys, Im trying to write a script (Password Reminder) that checks for an email address in a list and if it exists then email them but if the address doesn't send them to a registration page. For some reason even if the address is present my script sends the email and then proceeds to direct the user to the register page as well.. Could someone help please? elseif ($_GET['forgot'] == "y" && isset($_POST['femail'])){ $rootaddress = 'dom@ahead4.com'; $from = "administrator@sitename.co.uk"; $site = $_POST['femail']; $email = strtolower($_POST['femail']); $date = date('d, D, M Y'); $Lines = file("file.DAT"); foreach($Lines as $Key => $Val) { $Data[$Key] = explode("|", $Val); $fname = $Data[$Key][1]; $sname = $Data[$Key][0]; $match = strtolower($Data[$Key][11]); $pass = $Data[$Key][12]; if ($email == $match) { $subject = "Forgotten Password"; $messagebody = " Hello $fname $sname, You have requested a password reminder: Email Address: $match Password: $pass Date Requested: $date"; $headers = "From: $from"; mail($site, $subject, $messagebody, $headers); print "<p>Your password reminder will be with your shortly. Thank-you.</p>"; print "<meta http-equiv=\"refresh\" content=\"2;url=http://www.sitename.co.uk\">"; exit; } else { print "<meta http-equiv=\"refresh\" content=\"0;url=http://www.sitename.co.uk/?page=sorry\">"; } } } Could someone take a look for me please? Thanks Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 change this: print "<meta http-equiv=\"refresh\" content=\"2;url=http://www.sitename.co.uk\">"; to this: header("Location: http://www.sitename.co.uk"); and change this: print "<meta http-equiv=\"refresh\" content=\"0;url=http://www.sitename.co.uk/index.php?page=sorry\">"; to this: header("Location: http://www.sitename.co.uk/index.php?page=sorry"); Regards ACE Quote Link to comment Share on other sites More sharing options...
phpzone Posted June 30, 2008 Share Posted June 30, 2008 print "<p>Your password reminder will be with your shortly. Thank-you.</p>"; print "<meta http-equiv=\"refresh\" content=\"2;url=http://www.sitename.co.uk\">"; You cannot do this. A meta http-equiv should be in the top of your page, in the <head></head> section. However, I think you should be looking at using code such as: <?php exit( header('Location: http://www.sitename.co.uk') ); ?> Note, you cannot send a header if you have printed _anything_ to the page. So to avoid, turn output buffering on at the top of the page and then clear the buffer if you need to redirect: <?php ob_start(); print <<<_HEADER Welcome to so and so site.... _HEADER; // // do lookup for email address etc. // if ( $email_not_found ) { ob_clean(); exit( header('Location: http://www.sitename.co.uk/register') ); } else { // do email stuff print <<<_THANKS Your password has been reset and a copy of the new password sent to your email address. _THANKS; } ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 overall its layout is abit poor. Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted June 30, 2008 Author Share Posted June 30, 2008 Ok, well for the moment I've removed the parts where I have printed an http redirect. Lets assume I just want to either print 'Success' or 'Failure' once the checking has done. When I do this 'Failure' keeps printing multiple times until 'Success' pops up.. Your right about the structure of the code. I just need some help to get it into order. Think the multiple printing may be because of my foreach loop? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 yep Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted June 30, 2008 Author Share Posted June 30, 2008 The thing is, if I place my else statement outside of my loop nothing appears but a blank screen. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted June 30, 2008 Share Posted June 30, 2008 thats what the header("Location: www.whatever.com"); is for... Quote Link to comment 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.