0

I have controller example name by test.

In index method I will make session, it will store in database successfully, but when I want to read them in other method, it will make another session in database. For example:

public function index(){
     $this->session->set_userdata('test','test');
}
public function test(){
     echo $this->session->userdata('test');
}

It will echo nothing. And when I check the database, it made new row.

2
  • 1
    What outputs when you put this in your test-function? var_dump($this->session->all_userdata()); Commented Sep 2, 2011 at 13:20
  • I don't think echo from your controller propagates to your view, but var_dump($this->session->userdata('test')) does. So as @Tobias: what's the output from var_dump? Commented Sep 2, 2011 at 15:12

2 Answers 2

1

I've seen elsewhere (for example here) that Codeigniter has problems with cookies on localhost and that will cause the problems that you are describing because if the cookie is not valid Codeigniter won't be able to recognize the session and collect that information from the database. In order to verify this hypothesis you can upload your application to a real server and try it there.

Sign up to request clarification or add additional context in comments.

Comments

0

i face a similar issue and just found that the System's session library had some problem setting the cookie the it looks like

setcookie(
                $this->sess_cookie_name,
                $cookie_data,
                $expire,
                $this->cookie_path,
                $this->cookie_domain,
                $this->cookie_secure
            );

i just re wrote it with

setcookie(
                $this->sess_cookie_name,
                $cookie_data,
                $expire,
                $this->cookie_path,
                $this->cookie_secure
            );

and it worked out fine

Comments

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.