【发布时间】:2016-05-25 20:29:47
【问题描述】:
我找到了一个可用于我的网站的教程密码重置功能,因此我下载了文件并使用了代码。我不太喜欢他们的,所以我几乎把所有的都删了,保留了重要的部分。反正我是从here下载的,可惜现在不行了。
每当我输入电子邮件时,无论它是什么,它都会显示“无效电子邮件”。任何帮助将不胜感激。另外,我是 PHP 的一个小菜鸟,但我了解这里的所有代码。我的代码如下:
<?php include "base.php"; ?>
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="stylesheet" href="style2.css" type="text/css" />
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Forgot Password</title>
</head>
<body>
<div id="main"><h1>Forgot Password</h1>
<p>If you forgot your password, please enter the email associated with your account, and we will send you a reset link.</p>
<form action="" method="post" name="passwd" id="passwd">
<fieldset>
<label for="emailadd"><div>Email Address:</div></label><input id="emailid" name="emailid" type="text" placeholder="Your Account's Email"><br>
<input type="submit" value="Reset Password" />
</fieldset>
</form>
</div>
<?php
if(!empty($_POST['emailid']))
{
$emailaddress = mysqli_real_escape_string($_POST['emailid']);
if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $emailaddress)) // Validate email address
{
echo '<p id="msg"><center>That is an invalid email address. Please try again.</center></p>';
}
else
{
$query = "SELECT UserID FROM users where EmailAddress='".$emailaddress."'";
$result = mysqli_query($query);
$Results = mysqli_fetch_array($result);
if(count($Results)==1)
{
$encrypt = md5(XXXXXXXXXXXXXXXXXXX);
echo '<p id="msg"><center>Your password reset link has been sent to your email.</center></p>';
$to=$emailaddress;
$subject="Forgot Password";
$from = 'no-reply@XXXXXXXXXXXX.com';
$body='Hello, <br/> <br/>Your Membership ID is: '.$Results['id'].' <br><br>Click <a href="http://XXXXXXXXXXX.com/home/forgot/reset.php?encrypt='.$encrypt.'&action=reset">here</a> to reset your password, or follow the link below:<br><br>http://XXXXXXXXXXXX.com/home/forgot/reset.php?encrypt='.$encrypt.'&action=reset <br/> <br/>--<br>XXXXXXXXXXXX<br>Games, Tools, and so much more!';
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to,$subject,$body,$headers);
}
else
{
echo '<p id="msg"><center>Account not found. Please try again. </center></p>';
}
}
} elseif(!empty($_SESSION['LoggedIn']) && !empty($_SESSION['Username'])) {
echo "<meta http-equiv='refresh' content='0;http://www.XXXXXXXXXXXX.com/home/main.php'/>";
} else {
}
// include("html.inc");
?>
</body>
</html>
附: Base.php 连接到我的数据库,X 代表我的加密或我的网站地址。
提前致谢!
【问题讨论】:
-
测试它失败了,我看到 3 个选项
-
其他两个选项在哪里。我看不到他们。
-
if(!empty($_POST['emailid'])),if (!preg_match("/^[^@]{1,64}@[^@]{1,255}$/", $emailaddress)),if(count($Results)==1)
标签: php passwords forgot-password password-recovery