I want to limit access to certain elements of a user’s profile so that only the user can see them and not other logged in users. So far the is_logged_in function (see below) works fine, now I need to refine it so that it is limited to a specific user that is logged in.
I’m already including a user_id variable in my session data, so that’s available for use.
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
if($is_logged_in)
{
$this->index();
}
else
{
redirect('fooview');
}
}
you will need to know the user_id of the profile you are viewing, lets assume in your controller you have it as
$user_id.in your controller you can do
$is_owner = $this->session->userdata('user_id') == $user_id ? true : false;then pass it to your view as e.g.
$is_owner.then in your view simply have