Welcome Guest, Not a member yet? Register   Sign In
router query

(This post was last modified: 11-15-2022, 09:09 AM by badger.)

A single redirect is causing two redirects and I can't figure out why. The code is intended to catch any uri containing "logout"  and send it to the auth controller which will do the logout process.
Many thanks for any help/advice

in Routes I have only the following
if(in_array('logout',explode('/',uri_string()))) {
    log_message('error', 'send to auth::loginout');
    $routes->post('/(:any)', 'Auth::loginout');
} else {
    $routes->get('/(:any)', '\App\Controllers\External\Home::index');
    log_message('error', 'authNotRequired "' . uri_string().'" FINISHED');

In the Auth controller I have
    function loginout($par=false){
        // ..... the actual logout code will appear here but at the moment there is nothing
        log_message('error','auth::logged out now redirect to front');
        return redirect()->to('');

in my log file i see
    route begin -> `front/logout`
    send to auth::loginout
    auth::logged out now redirect to front                  <-- the auth controller now calls redirect to home
    route begin -> `home`                                          <-- this is where the router sees the uri for home
    authNotRequired "home" FINISHED                  <--  router is now finished with call to home
    route begin -> `home`                                          <-- but here the router has another call to home
    not logout
    authNotRequired "home" FINISHED

so the redirect to home in the Auth controller is called only once but the router sees it twice. The apache log confirms this
POST /front/logout
GET /home
GET /home

Stupid me. A moments reflection is worth a years experience. The second call to home was caused by the ajax call acting on the response.

Hey, that's how we learn.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

Theme © iAndrew 2016 - Forum software by © MyBB