0

I'm Using codeigniter frame work and i'm having some problems with session.

in my login form i ask for username and password, then if supplied credentials are valid, then i put them in to a session variable as this.

$user_session_data = array(
'username' => $this->input->post('username'),
'is_logged_in' => 1
);
$this->session->set_userdata($user_session_data);

everything works well before. but today i add codes in to some pages to set some error messages to session.

$error_array[]="There Is An Error When Inserting Data In To The Database";
$this->session->set_userdata(array('upload_errors' => $error_array));

after this done. i can log into the admin area. but i cant do any thing it always ask me to login again. i think the second code is overriding the loging session data.

any idea to solve this error?

2 Answers 2

4

please use this code to set session in codeigniter

$this->session->set_userdata('user_session', $user_session_data);
Sign up to request clarification or add additional context in comments.

Comments

0

You are calling $this->session->set_userdata() it twice , this will remove all old data and set new once.

So if you are using it for error you can use below code

If you want to show error codeigniter session library have function to do that

$this->session->set_flashdata('item', 'value');

Set value using above code and get that value using

$this->session->flashdata('item');

Reference : http://ellislab.com/codeigniter/user-guide/libraries/sessions.html

3 Comments

the previous error is now gone. but no it saying cannot modify header information headers already started.
sounds like your echoing something in your controller?
if you are using echo before header() or redirect() it will show cannot modify header information headers already started

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.