Reputation: 49833
How do you control from hooks files if the session and the cookies are enabled on user browser?
this is my code unfortunately it doesn't works:
cookie.php (/hooks) class Cookie {
function control_cookies_enabled()
{
$CI =& get_instance();
$CI->session->unset_userdata('enabled_cookies',false);
$CI->session->set_userdata('enabled_cookies','1');
if($CI->session->userdata('enabled_cookies') !== '1'){
redirect(site_url('home'));
}
}
}
then i call that in /config/hooks.php
$hook['pre_controller'] = array(
'class' => 'cookie',
'function' => 'control_cookies_enabled',
'filename' => 'cookie.php',
'filepath' => 'hooks'
);
Thanks.
Upvotes: 0
Views: 2694
Reputation: 7398
What you need to do is set up a base controller that will look after the session for you and split your logged in controllers from your logged out ones via inheritance. There is no need to do this in a hook.
Please see a previous answer of mine for more information.
Upvotes: 1