简体   繁体   中英

Any set backs if I initialize codeigniter session every time controller gets called?

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()
    {

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.

I don't think you should be using session_start() if you're having CodeIgniter manage your sessions (which you are if you're using CodeIgniter's set_userdata() / get_userdata() functions).

It says right at the top of the CI user docs that CI doesn't use PHP's native session handling, so this may be causing you trouble. The session is started automatically by loading the session library, either automatically if you put it in the config file or explicitly with $this->load->library('session'); .

http://codeigniter.com/user_guide/libraries/sessions.html

-Gus


Edit: I came across a CI forum post regarding IE/CI session issues. Apparently it's a well-known issue. http://codeigniter.com/forums/viewthread/211955/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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