CodeIgniter会话不断被破坏

时间:2015-07-18 17:49:39

标签: php codeigniter session

我正在使用一个使用CodeIgniter 2.1.3的旧应用程序。在开发期间,它在vhost上运行,可在http://vhostname/app访问(等于xampp / htdocs / project / app)。

我将实时系统1:1复制到我的开发系统(包含数据库和所有内容)。

系统使用会话为访问者(例如购物车)存储临时数据。我的问题:在我的开发环境中,每次刷新都会破坏会话。经过一些测试后,我发现它发生在system/core/Sessions.php

        // encryption was not used, so we need to check the md5 hash
        $hash    = substr($session, strlen($session)-32); // get last 32 chars
        $session = substr($session, 0, strlen($session)-32);

        // Does the md5 hash match?  This is to prevent manipulation of session data in userspace
        if ($hash !==  md5($session.$this->encryption_key))
        {
            log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.');
            $this->sess_destroy();
            return FALSE;
        }

但我完全不知道为什么会发生这种情况并慢慢耗尽这些想法。

live和dev系统之间唯一可见的区别:

更新: 至少我刚刚发现散列与加密密钥不匹配的原因。我将WordPress中的wp-head.php包括在内以获取对WordPress功能的访问权限。但似乎我的会话“在此时”被“破坏” - 没有包括会话保持活跃。

更新2: 好的,我想我越来越近了。我试图比较会话cookie,一个与wordpress包含版本和一个没有。实际上有很大的不同:

包含WordPress的cookie:

a:6:{s:10:\"session_id\";s:32:\"8e3b975d0b30f6b229f475b2f03947a0\";s:10:\"ip_address\";s:9:\"127.0.0.1\";s:10:\"user_agent\";[...]

没有WordPress:

a:6:{s:10:"session_id";s:32:"7451cd27e1b45d2c7b8a042ed6b2bf9e";s:10:"ip_address";s:9:"127.0.0.1";s:10:"user_agent";[...]

这些引号来自哪里?

谢谢!

1 个答案:

答案 0 :(得分:0)

检查配置文件中的会话设置

$config['sess_match_useragent'] = TRUE;

如果sess_match_useragent设置为true。然后把它弄错并尝试。

as codeigniter每次检查useragent并返回其值,如

Mozilla/5.0 (Windows NT 5.1; rv:13.0a1) Gecko/20120206 Firefox/13.0a1

OR

Mozilla/5.0 (Windows NT 5.1; rv:13.0a1) 

并检查cookie。有时候修剪user_agent并保存在cookie中,但要与导致此问题的完整返回值进行比较。

如果您使用数据库在codeingiter中保存会话

$config['sess_cookie_name']     = 'ci_session';
$config['sess_expiration']      = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie']  = FALSE;
$config['sess_use_database']    = TRUE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update']  = 300;
enter code here

然后在CI_session表中增加user_agent列长度。

相关问题