Welcome Guest, Not a member yet? Register   Sign In
CI Sessions - No user data
#21

[eluser]robjstanley[/eluser]
That could take a while and isn't it irrelivent? as the same exact problem occurs now.
#22

[eluser]toopay[/eluser]
take a look at http://ellislab.com/codeigniter/user-gui...sions.html : "Note: The Session class does not utilize native PHP sessions. It generates its own session data..bla..bla"... I want to help you debug your code, and i think we should fix it at CI spec, not php native session spec.
#23

[eluser]toopay[/eluser]
what CI version you use?
#24

[eluser]InsiteFX[/eluser]
Here is your problem, you are autoloading the session library the session library automatically starts the sessions! So you do not need to use session_start(); By doing that you are creating a new session everytime.
Code:
function __construct()
    {
        parent::Controller();
        session_start();     // <-- Remove this you our autolaoding the sessions no need to start it!
        //$this->logged_in();      
    }

InsiteFX
#25

[eluser]robjstanley[/eluser]
Code:
&lt;?php

class Login extends Controller {
    
    function __construct()
    {
        parent::Controller();
        //$this->logged_in();      
    }
    
    function index()
    {
         $data['content'] = 'login';
         $this->load->view('template',$data);        
    }
    
    function validate()
    {        
        $this->load->model('user_model');
        $id = $this->user_model->validate();
        
        if($id) // if the user's credentials validated...
        {
            $data = array(
                'user_id' => $id,
                'is_logged_in' => true
            );
            $this->session->set_userdata($data);
            redirect('/panel');
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }
}

Code:
&lt;?php

    class View extends Controller{
      
       function __construct()
        {
            parent::Controller();
       }
    
        function index()
        {
            $this->load->model('reviews_model');
            $this->load->model('news_model');
            $this->load->helper('img_helper');
                    
            $data['review'] = $this->reviews_model->latest();
            $data['recent'] = $this->reviews_model->recent();
            $data['news'] = $this->news_model->latest();
            
            $data['content'] = 'home';
            $this->load->view('template',$data);
        }
}
#26

[eluser]robjstanley[/eluser]
[quote author="InsiteFX" date="1301434996"]Here is your problem, you are autoloading the session library the session library automatically starts the sessions! So you do not need to use session_start(); By doing that you are creating a new session everytime.
Code:
function __construct()
    {
        parent::Controller();
        session_start();     // <-- Remove this you our autolaoding the sessions no need to start it!
        //$this->logged_in();      
    }

InsiteFX[/quote]

I added session_start for the native php sessions. i wasn't autoloading the session library.
#27

[eluser]toopay[/eluser]
Theres seems nothing wrong with that. What version of CI you use?
#28

[eluser]robjstanley[/eluser]
1.7.1
#29

[eluser]toopay[/eluser]
are you say : "i wasn’t autoloading the session library."...lol, i ask you before this and you say you set session in autoload. Check your autoload.php in config folder, and check if you set something like
Code:
$autoload['libraries'] = array('session');
#30

[eluser]robjstanley[/eluser]
I was autoloading it when i was using CI sessions, not when i was just using plain old PHP Sessions.




Theme © iAndrew 2016 - Forum software by © MyBB