dqwh1209 2014-12-16 23:18
浏览 61

在php中传递$ _SESSION

Currently been at this for few hours now and desperately need a fresh set of eyes. When log in takes place a form is loaded to test encrypted password and username against the database, as it stands there are no errors showing up in the form when it is run but simply when it is run it denies the data from the user currently in the database being passed through.

I also recieve the final else statement giving me "Access Denied" any help would be hugely appreciated just need a fresh set of eyes, thanks alot. also to add all the $data instances are fields within the database

<?php
$serverName = "localhost";
$username = "root";
$password = "";
$databaseName = "filestackusers";
$connect = new PDO("mysql:host=$serverName;dbname=$databaseName",$username, $password);
//encrypt pass and user for search
if(isset($_POST["username"]) && isset($_POST["password"]))
{
$FolderEncryption = md5($_POST['username']);
$passwordEncryption = md5($_POST['password']);
}
else
{
    echo "information not passed";
}


try
{
    //search if found load info
    $checkSqlStmt = $connect->prepare("SELECT * FROM users WHERE user_folder =
   :FolderEncryption AND password = :passwordEncryption");

    //bind
    $checkSqlStmt->bindParam(':FolderEncryption', $FolderEncryption, PDO::PARAM_STR);
    $checkSqlStmt->bindParam(':passwordEncryption', $passwordEncryption, PDO::PARAM_STR);

    //execute
    $checkSqlStmt->execute();

    $data = $checkSqlStmt -> fetchAll();

}
catch (Exception $ex)
{
    die("An error has occured! " . $ex->getMessage());
}

if ($data)
{
    if($_POST["username"] == $data[0]["username"]) //recheck email security
    {
        echo 'Access Granted';

        $_SESSION['userID'] = $data[0]['user_id'];
        $_SESSION['Username'] = $data[0]['username']; //set sessions
        $_SESSION['Password'] = $data[0]['password'];
        $_SESSION['Email'] = $data[0]['email'];
        $_SESSION['UserFolder'] = $data[0]['user_folder'];

        //load user info
        loadFileInformation();
    }
}
    else
    {
        echo "Access Denied";
    }
?>
  • 写回答

2条回答 默认 最新

  • doutou7740 2014-12-16 23:24
    关注

    You only echo access denied when $data evaluates to false. That can be the case when you don't assign it at all, which happens when you get an exception when executing the query. If there is no exception, fetchAll might still return false in case of an error.

    But also, if the query executes correctly but returns no rows, fetchAll() returns an empty array, which also evaluates to false in PHP. (I don't make this stuff up!)

    So whichever the case, it is due to the execution of the query.

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)