CodeIgniter-Checking session variable is already set or not when clicking each link or reloading page

牧云@^-^@ 提交于 2019-12-30 11:22:26

问题


I have a controller named admin,and all functions in the controller can be used if the session variable is set,so what are the best ways to check if the session is set ,when clicking each link in the page or reloading the pages...

for example: if i open my admin home page in multiple tabs in a browser and sign off from first tab, bt after that in the second tab all links a working properly

so i want to check if the session is set or not...

Thanks!


回答1:


If you want to check whether the session variable is set or not, then use this.

if($this->session->userdata('session_variable')) {

      // Do your code here
}

Meanwhile, if you want to check whether the session variable is set with a particular value, then you can use this.

if($this->session->userdata('session_variable') == "VALUE") {

      // Do your code here
}



回答2:


According to http://ellislab.com/codeigniter/user-guide/libraries/sessions.html "Retrieving Session Data",

$this->session->userdata('not_set') 

returns false.




回答3:


Simple join query solve your issue.

$this->db->select('*');
$this->db->from('first_table_name ftn');
$this->db->join('second_table_name stn', 'ftn.id = stn.id','left');
$query = $this->db->get();


来源:https://stackoverflow.com/questions/14556194/codeigniter-checking-session-variable-is-already-set-or-not-when-clicking-each-l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!