会话在Codeigniter中重定向后丢失 [英] Session lost after redirect in Codeigniter

查看:62
本文介绍了会话在Codeigniter中重定向后丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用codeigniter作为框架。

I'm using codeigniter as a framework.

首先,我使用 localhost ,但是当我更改为我的IP地址登录功能不再起作用。我发现会话在重定向到另一个控制器后丢失了。

Firstly, I use localhost but when I change to my IP address the login function doesn't work anymore. I found that the session is lost after redirect to another controller.

这是 print_r($ this-> session-> all_userdata());

[session_id] => 7b00fa0f8790f48d24446f9eb4e6aab2 
[ip_address] => 10.42.68.71 
[user_agent] => Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1
[last_activity] => 1285962398 
[user_data] =>

您可以看到它没有任何数据传递给 user_data ,但在测试时将其设置为重定向之前。

As you can see it doesn't have any data passed to user_data but it was set before redirect when I test.

我将控制器分为两个,第一个是用户->登录功能的处理程序,另一个是计划程序,它是我从用户控制器重定向的链接的处理程序。

I separate the controller to two which the first one is users -> handler of login function and another is planner which handler of the link that I redirect from users controller.

users.php (第一个控制器) :

users.php (first controller):

$this->load->model('users_model');
$this->load->model('mymodel');
$this->load->database();

$email = $this->input->post('email');

$pass = $this->input->post('password');

$type = $this->input->post('type');

// Authenticate the user
$userdata = $this->users_model->auth_user($email,$pass,$type);

if($userdata)
{
    $data = array('FIRSTNAME' => $userdata->FIRSTNAME, 
                  'LASTNAME' => $userdata->LASTNAME, 
                  'EMAIL' => $userdata->EMAIL,
                  'LOGIN' =>TRUE, 'TYPE' => $type);
    $this->session->set_userdata($data);
    redirect('planner/view_system','refresh');
}

planner.php (第二个控制器):

planner.php (second controller):

function __construct() {
    parent::__construct();

    if ( ! ($this->session->userdata('LOGIN')))
    { 
        print_r (var_dump($this->session->userdata('FIRSTNAME')));
        print_r($this->session->all_userdata());
    }
    $this->load->helper(array('form','html','url'));

这是我的配置

$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']    = FALSE;
$config['sess_table_name']      = 'ci_sessions';
$config['sess_match_ip']        = TRUE;
$config['sess_match_useragent'] = FALSE;
$config['sess_time_to_update']  = 300;


推荐答案

我遇到了完全相同的问题,这就是我要做的。
首先,转到文件 system / libraries / Session / Session.php
140 行上注释 session_start();
函数_configure 上,在 //下的几行注释为必填项

I have the exact same problem and here's what I do. First, go to file system/libraries/Session/Session.php. Comment session_start(); on line 140. On function _configure, comment few lines under // Security is king

//      ini_set('session.use_trans_sid', 0);
//      ini_set('session.use_strict_mode', 1);
//      ini_set('session.use_cookies', 1);
//      ini_set('session.use_only_cookies', 1);
//      ini_set('session.hash_function', 1);
//      ini_set('session.hash_bits_per_character', 4);

第二,转到文件 index.php 在您的根项目上。
Put, session_start(); <?php

Second, go to file index.php on your root project. Put, session_start(); below <?php

希望这会有所帮助。

这篇关于会话在Codeigniter中重定向后丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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