CodeIgniter sessions vs PHP sessions

后端 未结 5 866
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 00:31

I\'m relatively new to CodeIgniter and am making my first CI project in which there are user-accounts, etc. In the past, I have always used PHP\'s $_SESSION variable to this

5条回答
  •  猫巷女王i
    2020-12-08 01:10

    In my experience with CI I've encountered some anomalies with its sessions, but for most day-to-day needs the library is good and easy to work with. As it was pointed out, Flashdata is a very nice feature.

    If you choose to stay with CI's sessions, I'd strongly suggest to store sessions in a database and, additionally, encrypt cookies:

    $config['sess_encrypt_cookie'] = TRUE;
    $config['sess_use_database']   = TRUE;
    $config['sess_table_name']     = 'sessions';
    

    The database structure should be as follows:

    CREATE TABLE IF NOT EXISTS  `sessions` (
        session_id varchar(40) DEFAULT '0' NOT NULL,
        ip_address varchar(16) DEFAULT '0' NOT NULL,
        user_agent varchar(50) NOT NULL,
        last_activity int(10) unsigned DEFAULT 0 NOT NULL,
        user_data text NOT NULL,
        PRIMARY KEY (session_id)
    );
    

提交回复
热议问题