gpt4 book ai didi

php - 调用 PHP 目标文件导致页面不再加载

转载 作者:搜寻专家 更新时间:2023-10-30 20:25:30 24 4
gpt4 key购买 nike

所以我一直在为我的一个项目编写代码,在该项目中我必须为一个网站创建一个注册和登录系统,但我现在遇到了困难。我调用以下“UserLogin.php”文件:

class UserLogin
{
private $username;
private $firstName;
private $lastName;
private $userid;
private $emailaddr;
private $error;
private $db;
private $hash;
private $salt;
private $password

public function __construct($user, $pass)
{
$this['username'] = $user;
$this['password'] = $pass;
}

function getError()
{
return $this->error;
}



public function userLogin($username, $password)
{
if (checkUser($username)) {
if (checkPass($password)) {
$_SESSION['memberName'] = $this['username'];
$_SESSION['fName'] = $this['firstName'];
$_SESSION['lName'] = $this['lastName'];

return true;
}
} else {
$error = "Invalid username/password";
}

}



public function checkUser($username)
{
$mysqli = new mysqli('hostip', 'username', 'password', 'dbname', 3306);
$stmt = prepare($mysqli);

bind_param($stmt, "s", $username);
execute($stmt);
bind_result($stmt, $this['user_id'], $this['username'], $this['salt'], $this['hash']);

if (isset(fetch($stmt))) {
return false;
}
return true;
}



public function checkPass($password)
{
return hash_equals($this['hash'], crypt($password, $this['hash']));
//return (hash_hmac("sha256", $password, $this['salt']) === $this['hash']);
}

来自另一个文件,在用户输入用户名和密码后按回车键:

 include 'UserLogin.php';
$username = $_GET["username"];
$password = $_GET["pwd"];
$usersession = new UserLogin($username, $password);
echo "created";

$var = $usersession->userLogin($username, $password);
if ($var){
echo "Verified";
}

到目前为止,我还没有发现任何错误,但我的网站在点击登录按钮后没有完成加载。任何帮助将不胜感激。另请注意,我在 mysqli 变量中审查了我的实际数据库信息。

最佳答案

您在 private $password 之后缺少分号

关于php - 调用 PHP 目标文件导致页面不再加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36681086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com