我正在尝试使用PHP中的GET
方法登录。
我试过了:
的login.php
<?php
session_start();
require_once 'class.user.php';
$user_login = new USER();
if($user_login->is_logged_in()!="")
{
$user_login->redirect($web.$_SESSION['user_name']);
}
if(isset($_GET['user']) && isset($_GET['password']))
{
$uname = trim($_GET['user']);
$upass = trim($_GET['password']);
if($user_login->login($uname,$upass))
{
$user_login->redirect($uname);
}
}
?>
class.user.php
public function login($uname,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userName=:username");
$stmt->execute(array(":username"=>$uname));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() == 1)
{
if($userRow['userStatus']=="Y")
{
if($userRow['userAccess']=="Y")
{
if($userRow['userPass']==md5($upass))
{
$_SESSION['userSession'] = $userRow['userID'];
$_SESSION['loggedin_time'] = time();
$_SESSION['user_name'] = $userRow['userName'];
return true;
}
else
{
header("Location: signin.php?error");
exit;
}
}
else
{
header("Location: default.php");
exit;
}
}
else
{
header("Location: inactive.php");
exit;
}
}
else
{
header("Location: signin.php?error");
exit;
}
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
我总是收到错误消息:wrong details
我交叉检查了用户名&amp;用MySQL密码。他们是对的!
答案 0 :(得分:0)
这是因为您正在加密加密密码,从而产生wrong details
将if($userRow['userPass']==md5($upass))
更改为if($userRow['userPass']==($upass))
希望这会解决您的错误。