• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
could not redirect page when no session

#1
//helper function 

function check_session_set() {
   
    $session      = \Config\Services:Confusedession();
    if( $session->has( 'id' ) ) {}
    else {
    echo 'test';
    redirect()->to('public');
    }
    return true;
}



//basecontroller

    public function initController(\CodeIgniter\HTTP\RequestInterface $request,       \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
    {

    parent::initController($request, $response, $logger);
    helper(['common_helper','form', 'file']);
    $validation = \Config\Services::validation();
    $this->session = \Config\Services:Confusedession();

        check_session_set();

}

when i logout and click back button the page did not redirect to login page.but echo 'test' message shows.
is there redirect work in helper function
Reply

#2
// home controller
function user() {
if( $this->session->has( 'id' ) ) {
$tmp = view( 'user/index' );
$this->template( $tmp );}else {
return redirect()->to( site_url().'public/login' );
}}

above function is working ....
i want to give this function globally to check session every controller if has session then continue or go to login page.

i tried..
//helper
function check_session_set() {
$session = \Config\Services:Confusedession();
if( $session->has( 'id' ) ) {
} else {
return redirect()->to( site_url().'public/login' );
}
}
//in BaseController

public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
{
// Do Not Edit This Line
parent::initController($request, $response, $logger);
helper(['common_helper','form', 'file','filesystem']);
$validation = \Config\Services::validation();
$this->session = \Config\Services:Confusedession();
check_session_set();
}

this will not redirect page.
there is possible in ci 3.
In ci 4 how to do it
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.