Jump to content

[SOLVED] forgot password session error help


pixeltrace

Recommended Posts

hi,

 

i need help, i have a forgotpassword page and i am getting some errors which i can figure out how to solve.

below is my current code

<table width="778" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2" background="images/headerbg.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="226" align="left"><img src="images/header.gif" width="226" height="148"></td>
        <td> </td>
        </tr>
    </table></td>
    <td background="images/headerbg.gif"><img src="images/headeright.gif" width="16" height="148"></td>
  </tr>
  <tr>
    <td width="16" rowspan="2" align="left" valign="top" background="images/left.gif"><img src="images/left.gif" width="16" height="14"></td>
    <td width="745" align="center" valign="top"><table width="739" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="739"> </td>
        </tr>
        <tr>
          <td align="center"><h1 class="text4">Forgot Password</h1>
<span class="text8">A new password will be generated for you and send to the email address<br>
associated with your account, all you have to do is enter your
email address below.</span><br>
<br>
<?php session_start();
include 'db_connect.php';
$query="SELECT email, password FROM admin_user where email='$email'";
$result=mysql_query($query);

while($rec=mysql_fetch_assoc($result)){
$mail=$_SESSION['email']=$rec['email'];
}

if(mysql_num_rows($result)==1){

$password2 = $password;
$password1=md5($password);

if($_GET['cmd']=="update"){

$query2="UPDATE admin_user set `password`='$password1' where
`email` = '$email' ";

$result=mysql_query($query2)or die(mysql_error());


$Message = "";
$Message .= "This is a password change request\n";
$Message .= "that you requested from JobHiRings\n";
$Message .= "\n\n";
$Message .= "please keep this new password in a safe place\n";
$Message .="Your new password is:" .$password2."\n";
$Message .= "\n\n";


$Header = "webadministrator@jobhirings.com";
$To = "$email";
$Subject = "Your New Password"; 

mail($To,$Subject,$Message,"From: $Header");

echo " <div align='center'><b class='text3'>Thank you password changed!<br>
We have sent a copy to your email address!<div></b><br><br><a href='index.php' class='link2'>Please Login Now</a><br>
</td>
</tr><tr><td> </td></tr></table></td>
<td width='16' rowspan='2' align='right' valign='top' background='images/right.gif'><img src='images/spacer.gif' width='1' height='1'><img src='images/right.gif' width='16' height='14'></td>
</tr><tr><td valign='top'><img src='images/spacer.gif' width='746' height='10'></td>
</tr><tr><td background='images/footerbg.gif'><img src='images/footerleft.gif' width='16' height='43'></td>
<td background='images/footerbg.gif'><table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr><td height='10' colspan='2' align='left'><img src='images/spacer.gif' width='12' height='10'></td>
</tr><tr><td width='746' align='center' valign='top' class='footer'>Copyright © 2007 www.website.com. All Rights Reserved</td>
</tr></table></td><td background='images/footerbg.gif'><img src='images/footeright.gif' width='16' height='43'></td>
</tr></table></body></html>";
exit;
}

if($_GET['cmd']=="pro"){

echo"<div><form action='forgotpass.php?cmd=update ' method='POST'>
<b class='text3'>Please provide a new password</b><br><br>
<input type='password' name='password' maxlength='30'>
<br>
<br>
<input type='submit' value='New Password'>
</form></td>
</tr><tr><td> </td></tr></table></td>
<td width='16' rowspan='2' align='right' valign='top' background='images/right.gif'><img src='images/spacer.gif' width='1' height='1'><img src='images/right.gif' width='16' height='14'></td>
</tr><tr><td valign='top'><img src='images/spacer.gif' width='746' height='10'></td>
</tr><tr><td background='images/footerbg.gif'><img src='images/footerleft.gif' width='16' height='43'></td>
<td background='images/footerbg.gif'><table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>
<tr><td height='10' colspan='2' align='left'><img src='images/spacer.gif' width='12' height='10'></td>
</tr><tr><td width='746' align='center' valign='top' class='footer'>Copyright © 2007 www.website.com. All Rights Reserved</td>
</tr></table></td><td background='images/footerbg.gif'><img src='images/footeright.gif' width='16' height='43'></td>
</tr></table></body></html>";
exit;
}
}
?>


<form action="forgotpass.php?cmd=pro" method="POST">
<b class="text3">Email Address:</b> <input type="text" name="email" maxlength="30">
 
<input type="submit" value="Get New Password">
</form></td>
        </tr>
        <tr>
          <td> </td>
        </tr>
    </table></td>
    <td width="16" rowspan="2" align="right" valign="top" background="images/right.gif"><img src="images/spacer.gif" width="1" height="1"><img src="images/right.gif" width="16" height="14"></td>
  </tr>
  <tr>
    <td valign="top"><img src="images/spacer.gif" width="746" height="10"></td>
  </tr>
  <tr>
    <td background="images/footerbg.gif"><img src="images/footerleft.gif" width="16" height="43"></td>
    <td background="images/footerbg.gif"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="10" colspan="2" align="left"><img src="images/spacer.gif" width="12" height="10"></td>
      </tr>
      <tr>
        <td width="746" align="center" valign="top" class="footer">Copyright © 2007 www.website.com. All Rights Reserved</td>
      </tr>
    </table></td>
    <td background="images/footerbg.gif"><img src="images/footeright.gif" width="16" height="43"></td>
  </tr>
</table>

 

this is the error that i am getting

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/jobhi4/public_html/admean/forgotpass.php:6) in /home/jobhi4/public_html/admean/forgotpass.php on line 42

hope you could help me with this.

 

 

Link to comment
Share on other sites

hi,

 

i found a better one, and the sending of new password is working.

my problem now, its not updating the item in my table.

 

hope you could help me with this.

below is my current code for the password sending page

<?

include '../admean/db_connect.php';

// value sent from form 
$email_to=$_POST['email_to'];

// table name 
$tbl_name=applicant; 

// retrieve password from table where e-mail = $email_to(mark@phpeasystep.com) 
$sql="SELECT appid FROM $tbl_name WHERE email='$email_to'";
$result=mysql_query($sql);

// if found this e-mail address, row must be 1 row 
// keep value in variable name "$count" 
$count=mysql_num_rows($result);

// compare if $count =1 row
if($count==1){

$rows=mysql_fetch_array($result);

// create random password
$random_password=md5(uniqid(rand())); 
$new_password=substr($random_password, 0, ;

$id = $rows['appid'];


$sql="UPDATE applicant SET password ='$new_password' WHERE appid='$id'";
	mysql_query($sql) or die("error:".mysql_error());

// ---------------- SEND MAIL FORM ---------------- 

// send e-mail to ...
$to=$email_to; 

// Your subject 
$subject="JobHiRings: Your Acount Password Request"; 

// From 
$header="From: JobHiRings Administrator <administrator@jobhirings.com>"; 

// Your message 
$messages= "Your have requested for a new password \r\n";
$messages.="Your password is $new_password \r\n";
$messages.="You can now login to access your account using your email adress \r\n";
$messages.="and your new password. \r\n";
$messages.="Dont forgot to change your password for security reasons. \r\n";
$messages.="Thank You! \r\n";

// send email 
$sentmail = mail($to,$subject,$messages,$header); 

}

// else if $count not equal 1 
else {
echo "Not found your email in our database";
} 

// if your email succesfully sent 
if($sentmail){
echo "Your Password Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send password to your e-mail address";
}

?>

 

 

thanks!

Link to comment
Share on other sites

Hi,

 

sorry about that.

 

its working now.

i just needed to change the password to md5

// create random password
$random_password=md5(uniqid(rand())); 
$new_password=substr($random_password, 0, ;
$db_password = md5($new_password);
$id = $rows['appid'];


$sql="UPDATE applicant SET password ='$db_password' WHERE appid='$id'";
	mysql_query($sql) or die("error:".mysql_error());

 

 

FYI for the others who needs this kind of function.

 

thanks!

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.