简体   繁体   English

Codeigniter无法反序列化 - 错误会在设置flashdata时破坏会话

[英]Codeigniter can't unserialize - Error destroys session on setting flashdata

I have a problem with the CodeIgniter 2.1.3 Session Class. 我有CodeIgniter 2.1.3会话类的问题。

So I noticed this on setting some flashdata. 所以我在设置一些flashdata时注意到了这一点。 on other modules I haven't this error. 在其他模块上我没有这个错误。 It seems to be specific to that one module. 它似乎特定于那一个模块。

It happens when I run the form_validation and i set the flashdata -> in that moment the framwork wants to want to unserialize and got an error - that destroys my session. 它发生在我运行form_validation并且我设置了flashdata - >那时framwork想要反序列化并得到一个错误 - 这会破坏我的会话。

Error Log: 错误日志:

Severity: Notice  --> unserialize(): Error at offset 0 of 256 bytes /Applications/MAMP/htdocs/ges/system/libraries/Session.php 727

I tried all new Session classes of CI, also tried to trim before unserialize. 我尝试了所有新的CI类的CI,也试图在反序列化之前修剪。 But it still kills my session. 但它仍然会杀死我的会话。

Here is the part code of my controller (i had to change some var names cause security): 这是我的控制器的部分代码(我必须更改一些var名称导致安全性):

<?php

public function add($reg = false)
{

        if (!$reg)
                redirect('tickets');

        restrict_access(array(1,4), '/');
        $url = url_ci_decrypt($reg);
        parse_str($url, $url_data);

        $data                = $this->session_user->getSessionUserData();
        $data['title']       = 'XXXXX';
        $data['reg']         = $url_data;
        $data['reg']['name'] = $this->tickets_model->getTicketTypeText($url_data['type']);
        $data['reasons']     = $this->tickets_model->getTicketReasons();

        $this->form_validation->set_rules('message', 'Message', 'trim|required|min_length[20]|max_length[2000]');

        if ($this->form_validation->run() && $this->input->post()) {
                $posted  = $this->input->post();
                $newdata = array(
                        'x1' => $this->session->userdata['x1'],
                        'x2' => $this->session->userdata['x2'],
                        'x3' => $url_data['x3'],
                        'x4' => $url_data['x4'],
                        'x5' => 0,
                        'x6' => $posted['text']
                        );
                $result = $this->tickets_model->addTicket($newdata);
                if ($result === true) {
                        $this->session->set_flashdata('msg', 'message1');
                } else {
                        $this->session->set_flashdata('msg', 'message2');
                }
                redirect('/');
        } else if ($this->input->post()) {
                $posted       = $this->input->post();
                $data['text'] = strip_tags($posted['message']);
        }

        /* loading views */
}

// some more modules...

Here is also my config part for sessions: 这也是我的会话配置部分:

$config['sess_cookie_name']  = 'user_session';
$config['sess_expiration']       = 7200;
$config['sess_expire_on_close'] = true;
$config['sess_encrypt_cookie']  = true;
$config['sess_use_database']    = true;
$config['sess_table_name']       = 'user_sessions';
$config['sess_match_ip']         = false;
$config['sess_match_useragent'] = true;
$config['sess_time_to_update']  = 300;

It's works after I change "Collation" in PHPMyAdmin on all columns in "ci_session" table from "latin1_swedish_ci" to "latin2_general_ci". 在我将“ci_session”表中的所有列中的“Collat​​ion”从“latin1_swedish_ci”更改为“latin2_general_ci”后,它可以正常工作。

I'm from Poland, so in my national language I have letters like "ł", "ś" etc. When I add some flashdata with this letters, its been replaced for "?" 我来自波兰,所以用我的国语我有“ł”,“ś”等字母。当我用这些字母添加一些flashdata时,它被替换为“?” and after unserialize I have a bug. 在反序列化后我有一个bug。

Please check it in your project. 请在您的项目中进行检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM