使用PHP,mysql和PDO访问数据库时使用哈希密码登录错误。 [英] Login error with hash password using PHP, mysql and PDO for accessing database.

查看:113
本文介绍了使用PHP,mysql和PDO访问数据库时使用哈希密码登录错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用保存到我的数据库的哈希密码登录,但它不会重定向到我的主页面,即main.php,即使我输入了正确的密码。请帮帮我,我在这里待两天。



以下是我的代码:



<?php 
include(../ config / db_connection.php);
session_start();

$ query =SELECT * FROM sys_user WHERE username =:username;
$ statement = $ db-> prepare($ query);
$ statement-> execute(array('username'=> $ _POST [username]));

$ rows = $ statement-> fetchAll(PDO :: FETCH_ASSOC);
$ count = count($ rows);

if($ count == 1){
$ row = $ rows [0];
if(password_verify($ _ POST [password],$ row ['password'])){
$ _SESSION [username] = $ row [username];
header(Location:main.php);
}
else {
header(Location:../ index.php);
}
}
?>





非常感谢您提前。



我尝试了什么:



对我的代码进行大量操作。

解决方案

query =SELECT * FROM sys_user WHERE username =:username;


statement =


DB->制备(

I'm trying to login using hash password that save to my database but It won't redirect to my main page which is the main.php even though I input the correct password. Please help me, I'm stock here for two days.

Below is my code:

<?php
include("../config/db_connection.php");
session_start();

$query = "SELECT * FROM sys_user WHERE username = :username";
$statement = $db->prepare($query);
$statement->execute(array('username' => $_POST["username"]));

$rows = $statement->fetchAll(PDO::FETCH_ASSOC);
$count = count($rows);

if($count == 1) {
$row = $rows[0];
if(password_verify($_POST["password"], $row['password'])) {
$_SESSION["username"] = $row["username"];
header("Location: main.php");
}
else  {
  header("Location: ../index.php");
}
}
?>



Thank you very much in advanced.

What I have tried:

A lot of manipulation to my code.

解决方案

query = "SELECT * FROM sys_user WHERE username = :username";


statement =


db->prepare(


这篇关于使用PHP,mysql和PDO访问数据库时使用哈希密码登录错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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