只是寻找有关如何将urlencode应用到这段代码中的建议。它实际上正在工作,收到电子邮件时的问题,urlencode似乎无法正常工作。
function reset_password($email) {
$query = "DELETE from reset_password where email = $email";
$deletepass = mysql_query($query);
$code = substr(base64_encode(crypt('', '')), 0, 32);
$query2 = "INSERT into reset_password values ($email, '$code', " . time() . ")";
$insertval = mysql_query($query2);
$f = "SELECT userEmail from gn_users where email = $email";
$from = "***"; // sender
$f['userEmail']; // recepient
$message =
"From: *** <***>\r\n" . // email headers
"To: {$f['userEmail']} <{$f['userEmail']}>\r\n" .
'Subject: Reset Password' . "\r\n" .
"\r\n" .
"Hello\r\n" . // email imap_body(imap_stream, msg_number)
"\r\n" .
"A request has been made to reset your example.com web site password.\r\n" .
"\r\n" .
"To complete the request, click on the following link within 48 hours of the transmision of this email and follow the on screen instructions.\r\n" .
"\r\n" .
"index.php?page=reset-password&email=" . urlencode($email) . "&code=" . urlencode($code) . "\r\n" .
"\r\n" .
"Kind regards,\r\n" .
"\r\n" .
"The example.com Web Site";
$to = "$email";
$subject = "Test mail";
$message = "$message";
$from = "***";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";}
答案 0 :(得分:1)
我会尝试帮助你自己编写一些技巧,而不必依赖那些糟糕的代码。
您需要在多个,一口大小,易于执行的任务中分解任务。
我们走了:
uniqid()
,但这里有很多选项。因此,您生成的链接如下所示:http://test.com/reset.php?uid=443&hash=33rr3344rree22
。它无法真正被猜到,因为您需要知道用户ID和has。但为了确保,我们将在一小时或一天内到期。id
,email
,hash
,date_added
,并插入它(日期可以是{{ 1}},默认值为TIMESTAMP
)。CURRENT_TIMESTAMP
表,并向他发送确认邮件。这些步骤中的每一步都相当容易,或者您可以在网络上找到关于它们的大量信息。如果您花时间了解每一步,正确清理所有内容,并按照本书做事,您将学到很多东西。