Welcome Guest, Not a member yet? Register   Sign In
authentication
#1

Hi I am new to codigniter, and I am a beginner at php.

I am having trouble setting the "authentication system", that said, I can log in, log out and verify if user is logged in.

But I wanted to be able to prevent access to pages by a user that is not logged in and send the user to the login page.

I have tryed :
inside /Helpers/functions_helper.php
function check_session()
{
  if (!isset($_SESSION['login_utiliz'])) {
    return redirect()->to(base_url('login'));
  }
}


load it in Base_controller:
  protected $helpers = ['paths''functions'];

and use it on header view:

<?php
check_session()
?>
<!DOCTYPE html>
<html lang="en">


so that when a page that is loaded with this header it would check for the session attribute 'login_utiliz'

is my logic wrong, is there any other examples i can follow, I couldn't find answers on codeigniter 4 documentation.

Thank you for your help.
Reply


Messages In This Thread
authentication - by joseCarlos - 04-16-2020, 04:04 AM
RE: authentication - by Leo - 04-16-2020, 06:00 AM
RE: authentication - by joseCarlos - 04-16-2020, 06:26 AM
RE: authentication - by PHS - 04-16-2020, 10:46 AM
RE: authentication - by joseCarlos - 04-16-2020, 11:01 AM
RE: authentication - by Leo - 04-16-2020, 01:37 PM
RE: authentication - by joseCarlos - 04-16-2020, 02:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB