Welcome Guest, Not a member yet? Register   Sign In
Session Problem
#1

[eluser]Waqas Ahmad[/eluser]
Hi all,

it's my first post here. Can anybody guide me about following problem:

I have created a session in a controller using CI session, and then called it in an other controller where I printed the value of session. It is not working for any browser like IE7, Safari, Crome. But surprisingly it is working perfect in Firefox.

Notice:
1) I have tested the code on 2 different servers, both have PHP 5. On server 1, it is working perfect in all browsers, whereas it is not working on server 2.

2) PHP regular session is working on both of the servers, problem seems to be with CI session.

Can you tell me if it is some server configuration issue? or it is on CI end?

Following is the code which I am using to create the session and to display the session value.

Session Creator:
Code:
class Test extends Controller {
    function Test()
    {
        parent::Controller();
        $this->load->library('session');
    }

    function index()
    {
        $this->session->sess_destroy();        
        $this->session->sess_create();
        $this->session->set_userdata(array('user_logged_in' => true));
        echo("Session Created :: ".$this->session->userdata('user_logged_in'));
    }    
}

Session Display:

Code:
class Test2 extends Controller {
    function Test2()
    {
        parent::Controller();
        $this->load->library('session');
    }

    function index()
    {
        var_dump($this->session->userdata('user_logged_in'));
    }    
}

Thanks in advance :coolsmile:

Waqas
#2

[eluser]bigtony[/eluser]
This may not be the cause, but you don't need to do sess_destroy(), nor sess_create(), nor use an array in the session, and can therefore simplify your code a bit to:
Code:
function index()
    {
        $this->session->set_userdata('user_logged_in', true);
        echo("Session Created :: ".$this->session->userdata('user_logged_in'));
    }
The other thing I generally do is autoload the session library in config, since it tends to get used in many pages.
#3

[eluser]Waqas Ahmad[/eluser]
Thanks Grad Student,

I have tried this code as you told but still no success on Server 2.

I think there would be some Configuration issues on this server or there would be some settings in CodeIgniter.

But the point is what settings that would be? :-S
#4

[eluser]bigtony[/eluser]
This could be a long-shot, but you could try setting sess_match_useragent to false in your application/config/config.php file.

(P.S. GradStudent is just the forum status, not the name! :lol: )
#5

[eluser]Waqas Ahmad[/eluser]
Hi bigtony,

I am sorry to say, setting sess_match_useragent to false didn't work.

Oh, thanks for the correction. ;-P

[quote author="bigtony" date="1249397033"]This could be a long-shot, but you could try setting sess_match_useragent to false in your application/config/config.php file.

(P.S. GradStudent is just the forum status, not the name! :lol: )[/quote]




Theme © iAndrew 2016 - Forum software by © MyBB