Welcome Guest, Not a member yet? Register   Sign In
CI' session question
#5

[eluser]chmod[/eluser]
[quote author="iainco" date="1228002456"]Ok, that is all fine, can you show us the controller code where you can't seem to access the session data?[/quote]

Yes,my code is bellow:

login.php:
Code:
<?php
    class Loginto extends Controller{
        function Loginto(){
            parent::Controller();
            $this->load->model('center/loginto_model');
        }

        function index(){
            $data = array('title' => $this->lang->line('title_center_index'));
            $this->load->view('center/loginto_tpl',$data);
        }

        function checkUsernamePassword($username,$password){
            $resultCheckUsernamePassword = $this->loginto_model->checkUserLoginTo($this->input->post('username'),md5($this->input->post('password')),$this->lang->line('table_name_member'));
            if($resultCheckUsernamePassword){
                return true;
            }else{
                $this->form_validation->set_message('checkUsernamePassword',$this->lang->line('error_user_password'));
                return false;
            }
        }

        function iloginto(){
            $username = $this->input->post('username');
            $password = $this->input->post('password');

            $this->form_validation->set_rules('username','lang:username','trim|required|min_length[3]|max_length[15]|xss_clean');
            $this->form_validation->set_rules('password','lang:password','trim|required|min_length[8]|max_length[15]|xss_clean|callback_checkUsernamePassword');

            if($this->form_validation->run()){
                //set session
                $custom_session_data = array('username' => $this->input->post('username'),
                                            'isloginto' => true,
                                            'session_id_user' => $this->session->userdata('session_id'));
                $this->session->set_userdata($custom_session_data);


                if($this->session->userdata('forward')){
                    redirect($this->session->userdata('forward'),'refresh');
                }else{
                    $data = array('title' => $this->lang->line('title_mycenter_index'));
                    $this->load->view('center/mycenter_tpl',$data);
                }
            }else{
                $data = array('title' => $this->lang->line('title_center_index'));
                $this->load->view('center/loginto_tpl',$data);
            }
        }
    }
?>


mycenter.php:

Code:
<?php
class Mycenter extends Controller{
    function Mycenter(){
        parent::Controller();
        $this->load->model('common/security/security_model');
    }

    function index(){
        if ($this->security_model->isLoginTo() === true){
            $data = array('title' => $this->lang->line('title_mycenter_index'));
            $this->load->view('center/mycenter_tpl',$data);
        }else{
            $this->session->set_userdata('forward',$_SERVER['PHP_SELF']);
            redirect('center/loginto','refresh');
        }
    }
}
?>


Model:
Code:
<?php
class Security_model extends Model{
    function Security_model(){
        parent::Model();
    }

    function isLoginTo(){
        $session_id_user = $this->session->userdata('session_id_user');

        if (isset($session_id_user)){
            $this->db->where('session_id',$session_id_user);
            $this->db->from('ci_sessions');
            $query = $this->db->get();
            if ($query->num_rows() == 1){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }


    }

}
?>



my view:

mycenter_tpl.php

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
        &lt;title&gt;&lt;?=isset($title)?$title:'';?&gt;&lt;/title&gt;

        &lt;!--css link--&gt;
        &lt;link type="text/css" rel="stylesheet" href="&lt;?=CSS_URL;?&gt;css/index.css" /&gt;
        &lt;!--javascript--&gt;
        [removed][removed]
    &lt;/head&gt;
&lt;body&gt;

    &lt;?=$this->session->userdata('isloginto').'<---------&gt;'.$this->session->userdata('username') ;?&gt;
    <div><a >mybussiness</a></div>

&lt;/body&gt;
&lt;/html&gt;


in mycenter_tpl.php, the session data is displayed.but when I click the link: mybussiness

I will redirect to the controller mybussiness Controller.
But the session data can't access session data.
Why?

my mybussiness Controller:

Code:
&lt;?php
class Mybussiness extends Controller{
    function Mybussiness(){
        parent::Controller();
        $this->load->model('center/bussioness_model');
        $this->load->model('common/security/security_model');
    }

    function index(){
        if ($this->security_model->isLoginTo() === true){
            $data = array('title' => $this->lang->line('title_mybussiness_index'));
            $this->load->view('center/mybussiness_tpl',$data);
        }else{
            $this->session->set_userdata('forward',$_SERVER['PHP_SELF']);
            redirect('center/loginto','refresh');
        }
    }
}
?&gt;


Messages In This Thread
CI' session question - by El Forum - 11-29-2008, 09:45 AM
CI' session question - by El Forum - 11-29-2008, 10:54 AM
CI' session question - by El Forum - 11-29-2008, 11:31 AM
CI' session question - by El Forum - 11-29-2008, 11:47 AM
CI' session question - by El Forum - 11-29-2008, 11:02 PM
CI' session question - by El Forum - 12-01-2008, 06:53 AM
CI' session question - by El Forum - 12-01-2008, 10:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB