php - How to create a common function in codeigniter for checking if session exist? -


i creating application in users have login access various modules. need check if user session exist before providing access each module.

now checking session in each function / module / controller avoid unauthorized access.

if($this->session->userdata('userid')!=''){    something;  } 

is there better way this? can have common function similar

sessionexist(); 

such can called module / controller / function common whole project?

if should write common function such can called anywhere.

you want helper function, here is:

if ( ! function_exists('sessionexist')) {     function sessionexist(){         $ci =& get_instance();         return (bool) $ci->session->userdata('userid');     } } 

save file in application/helpers/ , include application/config/autoload.php file:

$autoload['helper'] = array('my_helper_file'); 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -