douqi4673
2014-08-11 21:03
浏览 43
已采纳

CodeIgniter会话未设置

The session is not set in the following case. It was working for me earlier. I am using CodeIgniter.

 public function authenticate(){
    $user = new Entity\User;
    //$user2 = new Entity\User;
    $user->username = "prayag@gmail.com";
    $user->password = "prayag";
    $userRepository = $this->doctrine->em->getRepository('Entity\User');
    $checkLogin = $userRepository->checkLogin($user);
    echo "Username => ". $checkLogin[0]->username;
    echo "ID => ". $checkLogin[0]->id;
    $this->load->library('session');
    $this->session->sess_destroy();

    if(!empty($checkLogin)){
        $CI =& get_instance();
        $this->session->set_userdata('user_id',$checkLogin[0]->id);

        $loggedIn = $this->session->set_userdata('user_id');    
            if($loggedIn !== TRUE){
                echo "session is not set";
                //echo $this->session->set_userdata('user_id');
            } else {
                    echo "session is set";
            }
        }
        else{
            echo "Username not found";  
        }
    }

I tried to solve it using the following post: https://stackoverflow.com/questions/10712250/w hat-is-the-proper-way-to-test-codeigniter-session-variable

图片转代码服务由CSDN问答提供 功能建议

在以下情况下未设置会话。 它在我之前工作。 我正在使用CodeIgniter。</ p>

  public function authenticate(){
 $ user = new Entity \ User; 
 // $ user2 =  new Entity \ User; 
 $ user-&gt; username =“prayag@gmail.com”; 
 $ user-&gt; password =“prayag”; 
 $ userRepository = $ this-&gt; doctrine-&gt; em  - &gt; getRepository('Entity \ User'); 
 $ checkLogin = $ userRepository-&gt; checkLogin($ user); 
 echo“Username =&gt;”。  $ checkLogin [0]  - &gt; username; 
 echo“ID =&gt;”。  $ checkLogin [0]  - &gt; id; 
 $ this-&gt; load-&gt; library('session'); 
 $ this-&gt; session-&gt; sess_destroy(); 
 
 if(! 空($ checkLogin)){
 $ CI =&amp;  get_instance(); 
 $ this-&gt; session-&gt; set_userdata('user_id',$ checkLogin [0]  - &gt; id); 
 
 $ loggedIn = $ this-&gt; session-&gt; set_userdata(  '用户身份');  
 if($ loggedIn!== TRUE){
 echo“session not set”; 
 // echo $ this-&gt; session-&gt; set_userdata('user_id'); 
} else {
  echo“session is set”; 
} 
} 
 else {
 echo“User name not found”;  
} 
} 
 </ code> </ pre> 
 
 

我尝试使用以下帖子解决它: https://stackoverflow.com/questions/10712250/w hat-is-the-proper-way-to-test-codeigniter -session-variable </ p> </ div>

3条回答 默认 最新

相关推荐 更多相似问题