普通网友 2012-05-26 04:12
浏览 57
已采纳

如果我每次调用控制器时初始化codeigniter会话,任何设置都会回退吗?

I having issues with Codeigniter sessions dying on IE randomly, I search everywhere and tried everything, the bug just wouldnt dissappear, i tried the function to check if ajax and wont sess_update() not working either, so my question is, what is the setback if I initialize the CI session every controller call? I have both native and CI sessions, but It would take me a few more days to change everything to Native sessions. its a temp fix.

  class Transactions extends Controller {

    function Transactions()
    {
        session_start();
        parent::Controller();   

        $this->load->model('Modelcontracts');
        $this->load->model('Modelsignup');
        $this->load->model('Modeltransactions');

        $this->session->set_userdata('account_id',$_SESSION['account_id']);
        $this->session->set_userdata('email',$_SESSION['email']);
        $this->session->set_userdata('account_type',$_SESSION['account_type']);
        $this->session->set_userdata('parent_account_id',$_SESSION['parent_account_id']);
        $this->session->set_userdata('accountrole_id',$_SESSION['accountrole_id']);
        $this->session->set_userdata('user_type_id',$_SESSION['user_type_id']);

    }



    function index()
    {
  • 写回答

2条回答 默认 最新

  • dtry54612 2012-05-26 10:08
    关注

    I never experience any problems with CodeIgniters sessions. Have you created the MySQL table for ci_sessions?

    The setback is basicly that it's an unlogical call. If that doesn't matter, then I can't see any setbacks with it.

    You could ease up the code like this though:

    $arr = array('account_id', 'email', 'account_type', 'parent_account_id', 'accountrole_id', 'user_type_id');
    
    foreach($arr as $h)
        if (isset($_SESSION[$h]))
            $this->session->set_userdata($h, $_SESSION[$h]);
        // else echo "Session [{$h}] doesn't exist!";
    

    Or extend your session library to do a

    foreach(array_keys($_SESSION) as $h)
        $this->CI->session->set_userdata($h, $_SESSION[$h]);
    

    When loaded.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试