douji9816 2016-02-15 10:01
浏览 44
已采纳

$ _POST突然抛出错误[重复]

This question already has an answer here:

I have this code that checks for login. It has been working fine but just stopped working suddenly.

public function checkLogin($_POST) {
        // fetching user by email
        $stmt = $this->conn->prepare("SELECT password_hash FROM users WHERE email = ?");

        $stmt->bind_param("s", $email);

        $stmt->execute();

        $stmt->bind_result($password_hash);

        $stmt->store_result();

        if ($stmt->num_rows > 0) {
            // Found user with the email
            // Now verify the password

            $stmt->fetch();

            $stmt->close();

            if (PassHash::check_password($password_hash, $password)) {
                // User password is correct
                return TRUE;
            } else {
                // user password is incorrect
                return FALSE;
            }
        } else {
            $stmt->close();

            // user not existed with the email
            return FALSE;
        }
    }

After checking my apache error log, I am seeing this error:

PHP Fatal error:  Cannot re-assign auto-global variable _POST

Any work around this?

</div>
  • 写回答

3条回答 默认 最新

  • dpwbc42604 2016-02-15 10:05
    关注

    Since PHP 5.4, you cannot use a superglobal as the parameter to a function

    $_POST is globally accessible. So you don't have to pass to your function.

    This is how your function should look like

    public function checkLogin() {
    $email = $_POST['email'];
    $password = $_POST['password'];
    
            // fetching user by email
            $stmt = $this->conn->prepare("SELECT password_hash FROM users WHERE email = ?");
    
            $stmt->bind_param("s", $email);
    
            $stmt->execute();
    
            $stmt->bind_result($password_hash);
    
            $stmt->store_result();
    
            if ($stmt->num_rows > 0) {
                // Found user with the email
                // Now verify the password
    
                $stmt->fetch();
    
                $stmt->close();
    
                if (PassHash::check_password($password_hash, $password)) {
                    // User password is correct
                    return TRUE;
                } else {
                    // user password is incorrect
                    return FALSE;
                }
            } else {
                $stmt->close();
    
                // user not existed with the email
                return FALSE;
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器