如果我的会话登录控制器是这样的话,如何创建注销按钮?
function login_user() {
$user_login = array(
'username'=>$this->input->post('username'),
'password'=>$this->input->post('password')
);
$data=$this->Infoserbilis_model->login_user($user_login['username'],$user_login['password']);
if($data) {
$session_data['logged_in'] = TRUE;
$this->session->set_userdata($session_data);
//$this->session->set_userdata('logged_in', $session_data);
redirect('Infoserbilis/admin_page', 'refresh');
} else {
echo '<script>alert("Invalid Username or Password");</script>';
redirect('Infoserbilis/index', 'refresh');
}
}
我在功能注销时尝试了$this->session->sess_destroy();
,但无济于事。提前致谢
public function logout() {
// Removing session data
$this->session->sess_destroy();
echo '<script>alert("Bye!");</script>';
redirect('Infoserbilis/index', 'refresh');
}
答案 0 :(得分:0)
好的,根据您的消息,$this->session->sess_destroy()
只是破坏当前会话,您需要手动重定向页面。在redirect()
函数
/**
* logout
*/
public function logout()
{
$this->session->sess_destroy();
redirect('/');
}
答案 1 :(得分:0)
function logout() {
$this->session->unset_userdata('is_searched');
redirect('CONTROLLER/login');
}
答案 2 :(得分:0)
您正在重定向到Infoserbilis
控制器中的public function index() {
if($this->session->userdata('is_logged_in') == true){
//load the required view
}
else {
redirect('controller/login');
}
}
功能。检查会话是否在该功能中有效。
这是一个例子:
login
或者您可以从logout
功能
public function logout() {
$this->session->sess_destroy();
redirect('controller/login');
}
public static class mylistitems
{
// public static List<Properties> mylistprop = new List<Properties>();
public static List<Properties> createdata(String name, String surname, String friend, String pet)
{
var DataProperties = new List<Properties>();
DataProperties.Add(new Properties { Name = name, SurName = surname, Friend = friend, Pet = pet });
return DataProperties;
}
public class Properties
{
public String Name { get; set; }
public String SurName { get; set; }
public String Friend { get; set; }
public String Pet { get; set; }
}
}