1

I want to know if there is any way to define custom fields in the sessions table of CodeIgniter.

By default, CodeIgniter stores session values in the following fields:

`session_id`, 
`ip_address`, 
`user_agent`, 
`last_activity`, 
`user_data`

What if I want to store a little more information in the sessions table using cookies? I mean, if I want to add username and want to change the field name session_id to SessionID.

Is it possible to achieve that without too much effort??

Expedito
  • 7,771
  • 5
  • 30
  • 43
Sizzling Code
  • 5,932
  • 18
  • 81
  • 138
  • 4
    everything that you store with `$this->session->set_userdata('key','value');` goes into the `user_data` column, so there is nothing else you have to do. as for `SessionID` instead of `session_id` you'll have to override the CI_Session class with your own. – Twisted1919 May 10 '13 at 19:29
  • What you are trying to accomplish would be better served with an authentication library http://stackoverflow.com/questions/346980/how-should-i-choose-an-authentication-library-for-codeigniter – user20232359723568423357842364 May 10 '13 at 19:30

1 Answers1

1

You can use set_userdata() function

like this

    $newdata = array(
                'username'  => 'sudz',
               'email'     => 'sudz@some-site.com'                 
           );

    $this->session->set_userdata($newdata);

you can't change session_id its used by codeigniter, instead you can define your own session_id with defferent name. or you have to override the CI_Session class.

Sudz
  • 4,268
  • 2
  • 17
  • 26