我试图设置密码重置请求,其中链接通过电子邮件发送给用户以重置我的网站上的密码,但PHP文件并未从我的表单中获取值。我将表单嵌入到我的PHP中只是为了让方法起作用,但对于我的格式化,我需要将表单分开。它适用于嵌入的表单,但如果我的表单在HTML中单独存在,则无法工作。我的表单HTML -
<form action="" method="post">
<p>Email Address: <input type="email" name="email" size="50" maxlength="255">
<input type="submit" name="submit" value="Get New Password"></p>
</form>
我的PHP文件(&#34; settings.php&#34;是我的数据库文件) -
<?php
$email=$_GET['email'];
include("settings.php");
connect();
$q="select email from users where email='".$email."'";
$r=mysql_query($q);
$n=mysql_num_rows($r);
if($n==0){echo "Email id is not registered";die();}
$token=getRandomString(10);
$q="insert into tokens (token,email) values ('".$token."','".$email."')";
mysql_query($q);
function getRandomString($length)
{
$validCharacters = "ABCDEFGHIJKLMNPQRSTUXYVWZ123456789";
$validCharNumber = strlen($validCharacters);
$result = "";
for ($i = 0; $i < $length; $i++) {
$index = mt_rand(0, $validCharNumber - 1);
$result .= $validCharacters[$index];
}
return $result;}
function mailresetlink($to,$token){
$subject = "Forgot Password";
$uri = 'http://'. $_SERVER['HTTP_HOST'] ;
$message = '
<html>
<head>
<title>Forgot Password</title>
</head>
<body>
<p>Click on the given link to reset your password <a href="'.$uri.'/reset.php?token='.$token.'">Reset Password</a></p>
</body>
</html>
';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: Admin<noreply@ca>' . "\r\n";
if(mail($to,$subject,$message,$headers)){
echo "We have sent the password reset link to your email id <b>".$to." </b>";
}}
if(isset($_GET['email']))mailresetlink($email,$token);
?>
答案 0 :(得分:1)
您在发布帖子请求时正在使用$_GET
。
您必须使用$_POST
试试这个:
$email = $_POST['email'];