Welcome Guest, Not a member yet? Register   Sign In
Opinion required - user authentication
#1

[eluser]Unknown[/eluser]
Hi,

As part of learning codeigniter I wanted to implement a function into my simple website to check if the user was logged in and if not prevent access to each section of the site. Rather than repeating code in each model or class I wanted it in just one place

After some investigation on these forums I found the following solution.

http://ellislab.com/forums/viewthread/206475/

Its basically creating a helper file with the following code

if( ! function_exists('site_authentication'))
{
function site_authentication()
{
$CI =& get_instance();
if($CI->session->userdata('login_data'))
{
$login_data_array = $CI->session->userdata('login_data');

if(! isset($login_data_array['is_logged_in']) || $login_data_array['is_logged_in'] !== true)
{
redirect('loginout');
}
}
else
{
redirect('loginout');
}
}
}

My only concern before I do this is the redirect when the user IS logged in. As this will change depending on the function/page the user is on, it cannot direct to a particular page right?

Should I just leave it blank? i.e. redirect the user to an error page if not logged in, or do nothing if they are logged in? and let the model/controller take care of it depending on the specific function/area?

Any opinions on this would be greatly appreciated!!

Thanks in advance!




Theme © iAndrew 2016 - Forum software by © MyBB