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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?