Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP脚本使用会话数据进行登录,是否存在安全风险_Php_Security_Login - Fatal编程技术网

PHP脚本使用会话数据进行登录,是否存在安全风险

PHP脚本使用会话数据进行登录,是否存在安全风险,php,security,login,Php,Security,Login,我在这里使用脚本: 我根据自己的需要修改了它,但我在脚本中看到了这一部分: // if user has an active session on the server elseif (!empty($_SESSION['user_name']) && ($_SESSION['user_logged_in'] == 1)) { $this->loginWithSessionData(); // checking for

我在这里使用脚本:

我根据自己的需要修改了它,但我在脚本中看到了这一部分:

// if user has an active session on the server
    elseif (!empty($_SESSION['user_name']) && ($_SESSION['user_logged_in'] == 1)) {

        $this->loginWithSessionData();      

        // checking for form submit from editing screen
        if (isset($_POST["user_edit_submit_name"])) {

            $this->editUserName();

        } elseif (isset($_POST["user_edit_submit_email"])) {

            $this->editUserEmail();

        } elseif (isset($_POST["user_edit_submit_password"])) {

            $this->editUserPassword();

        }
我不太确定会话变量是如何工作的,因为在服务器上,从技术上讲,它们不能直接更改,但是这部分代码表明,如果有人弄乱了cookies,它可以间接更改

private function loginWithSessionData() {

    $this->user_name = $_SESSION['user_name'];
    $this->user_email = $_SESSION['user_email'];

    // set logged in status to true, because we just checked for this:
    // !empty($_SESSION['user_name']) && ($_SESSION['user_logged_in'] == 1)
    // when we called this method (in the constructor)
    $this->user_is_logged_in = true;        

}
我不确定这是否可能,但如果我弄乱了cookies,设置username=x,运气好,并将is_logged_设置为1,那么用户可以访问吗?我确信有一种更安全的方法来验证会话,或者Cookie本身也有自己的验证类型,比如检查机器散列,并且该散列也必须与我们存储在服务器上的散列相匹配?我应该使用一个名为iftodaywasarainyday的随机字符串,并在内部对其进行注释,以便知道该值与我的is_logged_相对应,或者它是否重要,而不是像user_logged_那样简单


我会对这个主题做更多的阅读,但我想我接受了作者的说法,因为页面上的前三个词是“简单、干净、安全”这个网站看起来确实不错,但当我重构代码时,有很多todo语句让我担心它的工作正在进行中,而不是一个完成的脚本。会话数据存储在服务器端。实际数据根本不在cookie中。cookie只是一个ID,让服务器知道要加载哪个会话数据。用户不能修改此会话数据,除非您允许他们通过编写代码来修改。会话数据存储在服务器端。实际数据根本不在cookie中。cookie只是一个ID,让服务器知道要加载哪个会话数据。用户无法修改此会话数据,除非您允许他们通过编写代码进行修改