在以下情况下未设置会话。它早些时候对我有用。 我正在使用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";
}
}
我尝试使用以下帖子解决它:https://stackoverflow.com/questions/10712250/w hat-is-the-proper-way-to-test-codeigniter-session-variable
答案 0 :(得分:0)
$this->session->sess_destroy();
之后
不应该像session_start();
?
或者在代码中间销毁会话的重点是什么?
答案 1 :(得分:0)
更改此行
$loggedIn = $this->session->set_userdata('user_id');
到
$loggedIn = $this->session->userdata('user_id');
答案 2 :(得分:0)
你加载了会话库吗
即。 $this->load->library('session');
另外,转换代码
$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";
}
}
到
if($this->session->userdata('user_id')!=true)
{
echo "session is not set";
//echo $this->session->set_userdata('user_id');
}
else
{
echo "session is set";
}