php 没有从生成的 url 中获取键和值

标签 php mysql forms email

我正在尝试使用 PHP 创建忘记密码和密码重置模块。

  1. 用户输入电子邮件 ID 后,我从 MySQL 中获取与电子邮件 ID 匹配的记录。我能够获取记录。

    我的重置密码表单:

    <html>
      <body>
        <form method="post" action="sendlink.php">
          <p>Enter Email Address To Send Password Link</p>
          <input type="text" name="email">
          <input type="submit" name="submit_email">
        </form>
      </body>
    </html>
    
  2. 我正在使用电子邮件 ID 和密码创建一个链接,并将其作为邮件发送给用户。我可以发送电子邮件。我提供了一部分代码,使我能够发送带有链接的电子邮件。

    <?php
    if(isset($_POST['submit_email']) && $_POST['email'])
    {
      require 'connect.php';
      $email = $_POST['email'];
      $select=mysqli_query($connection, "select * from users where email='$email'");
      if(mysqli_num_rows($select)==1)
      {
        while($row=mysqli_fetch_array($select))
        {
          $email=$row['email'];
          $pass=$row['pass'];
        }
        $link="<a href='www.mywebsite.com/reset_pass.php?key=".$email."&?reset=".$pass."'>Click to reset password.</a>";
        require_once "phpmailer/class.phpmailer.php";
        $mail = new PHPMailer(true);
        $mail->CharSet =  "utf-8";
    

    这是由其他代码继续发送邮件。这部分工作正常,我正在收到邮件。

  3. 当我单击邮件中收到的链接时,我打算打开一个表单以使用链接中提供的 reset_pass.php 重置密码。

以下是生成的链接:

http://www.mywebsite.com/reset_pass.php?key=user@theshoecompany.com&?reset=39eb0152f5a43c08169716dbf158f08e

打开表单接受新密码的代码:

<?php
if($_GET['key'] && $_GET['reset'])
{
  $email=$_GET['key'];
  $pass=$_GET['reset'];
  require('connect.php');
  $query = "SELECT * FROM `users` WHERE email='$email' and pass='$pass'";
  $result = mysqli_query($connection, $query) or die(mysqli_error($connection));
  $count = mysqli_num_rows($result);


//3.1.2 If the posted values are equal to the database values, then session will be created for the user.
if ($count == 1)
  {
    ?>
    <form method="post" action="submit_new.php">
    <input type="hidden" name="emailnew" value="<?php echo $email;?>">
    <p>Enter New password</p>
    <input type="password" name='passwordnew'>
    <input type="submit" name="Submit">
    </form>
    <?php
  }
}
else {
  echo "<script>
                alert('could not get email or password');
                </script>";
}
?>

使用上面的代码,我想打开一个表单供用户输入新密码。但是电子邮件和密码的值并未从链接中发布。浏览器打开空白页面,加载它并保持空白,而不打开表单接受密码。

我该如何纠正这个问题?

最佳答案

您的表单方法是 POST,您应该从 $_POST 而不是 $GET 获取值。

如果方法是 POST,输入值对将不会显示在 URL 中,但会显示在 HTTP 请求正文中。

关于php 没有从生成的 url 中获取键和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44448808/

相关文章:

php - PDO 查询不返回行

mysql - 如何从 2 个表中进行选择并从一个表中获取最高值?

c# - 在 Entity Framework 中区分 MySQL 和 SQL Server

php - 需要重新认证 : INSERT base64 to BLOB in mySQL database

php - foreach 给我同一行四次(PHP、Active Record、CodeIgniter)

php - Laravel 5 中 S3 flysystem 适配器的路径不正确

php - 以滴答为单位的 UTC 时间(自 01/01/0001 00 :00:00)

php - 我的 UNION ALL 查询需要建议

php - 如果用户名已注册,如何抛出错误消息

JavaScript 表单验证 : understanding function call