我从一个网站上得到了这段代码,我一直在修改它以满足我的需求。我面临的问题是,密码重置页面并没有通过php邮件发出新的密码,而是在刷新页面,用户被困在php包含文件而不是网站上。
我知道一些php,但这似乎超出了我的能力。在尝试了不同的东西之后,我请求帮助:)
我希望这是一个简单的解决方案。提前感谢您的帮助和代码片段。
<?php
include 'dbc.php';
/******************* ACTIVATION BY FORM**************************/
if ($_POST['doReset']=='Reset')
{
$err = array();
$msg = array();
foreach($_POST as $key => $value) {
$data[$key] = filter($value);
}
if(!isEmail($data['user_email'])) {
$err[] = "ERROR - Please enter a valid email";
header("Location: index.html?p=unknownuser");
}
$user_email = $data['user_email'];
//check if activ code and user is valid as precaution
$rs_check = mysql_query("select id from users where user_email='$user_email'") or die (mysql_error());
$num = mysql_num_rows($rs_check);
// Match row found with more than 1 results - the user is authenticated.
if ( $num <= 0 ) {
$err[] = "Error - Sorry no such account exists or registered.";
header("Location: index.html?p=unknownuser");
//exit();
}
if(empty($err)) {
$new_pwd = GenPwd();
$pwd_reset = PwdHash($new_pwd);
//$sha1_new = sha1($new);
//set update sha1 of new password + salt
$rs_activ = mysql_query("update users set pwd='$pwd_reset' WHERE
user_email='$user_email'") or die(mysql_error());
$host = $_SERVER['HTTP_HOST'];
$host_upper = strtoupper($host);
//send email
$message =
"Here are your new password details ...\n
User Email: $user_email \n
Passwd: $new_pwd \n
Thank You
Administrator
$host_upper
______________________________________________________
THIS IS AN AUTOMATED RESPONSE.
***DO NOT RESPOND TO THIS EMAIL****
";
mail($user_email, "Reset Password", $message,
"From: \"Client Password Reset\" <clientservices@example.com>\r\n" .
"X-Mailer: PHP/" . phpversion());
header("Location: index.html?p=newpassword");
exit();
}
}
/*
mail($user_email, "Reset Password", $message,
"From: \"Client Registration\" <clientservices@example.com>\r\n" .
"X-Mailer: PHP/" . phpversion());
$msg[] = "Your account password has been reset and a new password has been sent to your email address.";
//header("Location: index.html?p=newpassword");
//$msg = urlencode();
//header("Location: forgot.php?msg=$msg");
//exit();
}
}
*/
?>
<script language="JavaScript" type="text/javascript" src="jquery/jquery-1.6.4.min.js"></script>
<script language="JavaScript" type="text/javascript" src="jquery/jquery.validate.js"></script>
<script>
$(document).ready(function(){
$("#actForm").validate();
});
</script>
<?php
/******************** ERROR MESSAGES*************************************************
This code is to show error messages
**************************************************************************/
if(!empty($err)) {
echo "<div class=\"msg\">";
foreach ($err as $e) {
echo "* $e <br>";
}
echo "</div>";
}
if(!empty($msg)) {
echo "<div class=\"msg\">" . $msg[0] . "</div>";
}
/******************************* END ********************************/
?><div id="clientLogin">You are about to request a reset of your client account password | <a href="?p=login" class="clientLogin">Login</a><br>
<form action="forgot.php" method="post" name="actForm" id="actForm" style="margin-top:5px;">
Your Email <input name="user_email" type="text" class="required email" id="txtboxn" size="25"><input name="doReset" type="submit" id="doLogin3" value="Submit" class="button"></form></div>发布于 2011-10-02 04:47:06
您必须:
mail($usr_email, "Reset Password", $message...);当它看起来你应该有
mail($user_email, "Reset Password", $message...);请注意,您使用的是$usr_email而不是$user_email。
这就是为什么没有发送电子邮件的原因。然后,看起来用户被重定向到index.html?p=newpassword,因此根据页面的内容,它可能看起来只是在重新加载同一个页面。
更新:
此外,您有一个值为Submit的元素doReset,并且在您的PHP代码中,您正在检查$_POST['doReset'] == Reset而不是Submit。
<input name="doReset" type="submit" id="doLogin3" value="Submit" class="button">将if ($_POST['doReset']=='Reset')更改为if ($_POST['doReset']=='Submit')
https://stackoverflow.com/questions/7622854
复制相似问题