严格标准:m_auth中仅应通过引用传递变量 [英] Strict Standards: Only variables should be passed by reference in m_auth

查看:68
本文介绍了严格标准:m_auth中仅应通过引用传递变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为使用MVC编程的项目开发登录系统,并遇到此错误.这是代码,问题所在的行是#31

I am working on a login system for a project using MVC programming and ran into this error. Here is the code, the problem line is #31

此登录系统是一个教程,我一直在按原样进行操作.我已阅读PHP 5的某些版本问题?不确定,希望有人可以帮助我.

This login system is a tutorial, I have been working through it exactly as is. I've read there are some version issues with PHP 5? Not sure, hopefully somebody could assist me.

问题行:

$stmt->bind_param("ss", $user, md5($pass . $this->salt));

代码:

<?php

/*
    Authorization Class
    deal with auth tasks
*/

class Auth
{
private $salt = 'j4H9?s0d';

/*
    Constructor
*/
function __construct()
{
}

/*
    Functions

*/
function validateLogin($user, $pass)
{
    // access db
    global $Database;

    // create query
    if ($stmt = $Database->prepare("SELECT * FROM users WHERE username = ? AND password = ?"))
    {
        $stmt->bind_param("ss", $user, md5($pass . $this->salt));
        $stmt->execute;
        $stmt->store_result();

        // check for num rows
        if ($stmt->num_rows > 0)
        {
            // success
            $stmt->close();
            return TRUE;
        }
        else
        {
            // failure
            $stmt->close();
            return FALSE;
        }
    }
    else
    {
        die("ERROR: Could not prepare MySQLi statement.");
    }
}

function checkLoginStatus()
{
    if (isset($_SESSION['loggedin']))
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}

function logout()
{
    session_destroy();
    session_start();
}
}

推荐答案

bind_param的参数是对变量的引用.您不能在那里使用md5().您需要先将其保存到变量中.

bind_param's params are references to variables. You can't use md5() there. You need to save it to a variable first.

$userPass = md5($pass . $this->salt);
$stmt->bind_param("ss", $user, $userPass);

这篇关于严格标准:m_auth中仅应通过引用传递变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆