使用codeigniter失去会话功能

时间:2013-05-15 14:29:09

标签: codeigniter codeigniter-2

所以我使用session来保存用户名,然后检查它是否存在。如果是,则使用它来更新与当前交易相关的内容。以下是我的代码:

public function update_edit()
    {
            /* echo " //// INSIDE UPDATE EDIT "; */

             $this->form_validation->set_rules('fullname', 'الاسم الكامل', 'isset|required|min_length[6]|max_length[100]');
                //echo 'Username: ';
                //check that there are no form validation errors
                if($this->form_validation->run() == FALSE)
                {   
                     echo " //// INSIDE FORM VALIDATION"; 
                    if(($this->session->userdata('username')!=""))
                    {
                                             echo " //// INSIDE SESSION VALIDATION"; 
                        $data = array();
                        $session_user = $this->session->userdata('username');
                        if(isset($session_user) && $session_user != '' && $session_user != null)
                        {

                            $data = $this->profileModel->load_user_editable_data($session_user);
                            $this->load->view('layout/header');
                            $this->load->view('profile_edit', $data);
                            $this->load->view('layout/footer');
                        }else{
                            $this->error_page();
                        }

                    }else{
                        //$this->load->view('login');
                        $this->login();
                    }
                }else{
                    echo "dasdaskhdkjashjdas";
                    $session_user = $this->session->userdata('username');
                    echo "Session User: " . $session_user;
                    if(isset($session_user) && $session_user != '' && $session_user != null)
                    {
                        echo "going to update;";
                        $complete = $this->profileModel->update_profile($session_user); 
                        echo "<br>finished updating...";
                        if($complete == 1)
                        {       
                            echo "Complete  = " . $complete;
                            $this->load->view('layout/header');
                            $this->load->view('update_complete');
                            $this->load->view('layout/footer');
                        }elseif($complete == 2){
                            echo "Complete  = " . $complete;

                            $this->error_page();
                        }

                    }
                }

    }

这里的问题是在echo dasdaskhdkjashjdas之后,没有任何会话检查不起作用。我打印了值,它是空的。在函数运行良好并加载数据之前,这怎么可能呢?该函数应该检查已加载的数据是否已更改,然后提交该新数据。

请帮助:)

1 个答案:

答案 0 :(得分:0)

改变这个:

if(isset($session_user) && $session_user != '' && $session_user != null)

到此:

if(!empty($session_user))