Jump to content

[SOLVED] Annoying Problem


Schlo_50

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

       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;
}
?>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.