Welcome Guest, Not a member yet? Register   Sign In
Filter/Session Issue
#1

(This post was last modified: 01-21-2024, 07:37 AM by jsurp2001.)

Hello all,
This may be a quick fix, something I am overlooking regarding sessions! 
I'm using Version 4.4.4.
I have a few filters: dashboard, admin, and developer.
Everything has been working fine and then suddenly I cannot access the developer area.
I have searched and found nothing addressing something similar to this. I can't figure it out.
When I dump the session variables in the developer filter the only item appearing is the '__ci_last_regenerate' entry, causing the filter to send me to the dashboard.
The dashboard and admin filter is working properly and when I dump the session variables, everything is there. When I look at the CI toolbar, everything is there too. The session data persists throughout the application just not in the developer filter.
I am not sure what I am overlooking. Any help will be much appreciated! Thank you!!
Reply
#2

Can you show us your filter code?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 01-21-2024, 04:21 PM by jsurp2001.)

(01-21-2024, 10:28 AM)InsiteFX Wrote: Can you show us your filter code?

Here is the dashboard filter:
Code:
<?php

namespace App\Filters;

use App\Models\AuthModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

class Dashboard implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = null)
    {
        $AuthModel = new AuthModel();

        helper(['user']);

        if(!session('dashboard'))
        {
            log_user_activity('filter-not-dashboard-user', 'Attempted to access <b>dashboard</b>.<br/>Redirected to home page.');
            return redirect()->with('session_alert', 'warning|Unauthorized Area!|You do not have authorization to access the previous area.')->to(site_url());
        }
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {

    }
}
Here is the developer filter:
Code:
<?php

namespace App\Filters;

use App\Models\AuthModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Filters\FilterInterface;

class Developer implements FilterInterface
{
    public function before(RequestInterface $request, $arguments = null)
    {
        $AuthModel = new AuthModel();

        helper(['user']);

        if(!session('developer'))
        {
            log_user_activity('filter-not-developer', 'Attempted to access <b>developer</b> area.<br/>Redirected to dashboard.');
            return redirect()->with('session_alert', 'warning|Unauthorized Area!|You do not have authorization to access the previous area.')->to(site_url('dashboard'));
        }
    }

    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
    {

    }
}

Once the filter sends me to the dashboard, I am still able to see the session data. My filters have been working fine for months, I'm not sure what is going on. And now my admin filter is kicking me to the dashboard. Thank you!!

1/21/2023 @ 1:14pm: I have also tried commenting out the code, leaving a completely blank method, and nothing, no session data when the page loads which is strange because you would think that my other filter, before that one which determines if the user is logged in, would send me to the login page.

1/21/2023 @ 4:10pm: I just noticed that there are 2 ci_session cookies:
https://drive.google.com/uc?export=view&...A9LH_kRQur
Reply
#4

Do you have a lot of session files in the writeable folder? if so delete them all and try again.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(01-21-2024, 11:02 PM)InsiteFX Wrote: Do you have a lot of session files in the writeable folder? if so delete them all and try again.

I am using the database driver for my sessions so everything is stored in the ci_sessions table. I’ve deleted all the cookies for the web application and emptied the sessions table in the database and a second ci_sessions cookie still appears when I open the admin page after bypassing the filter. I’ve noticed that the second ci_session cookie appears when I do this and disappears as soon as I leave the page.
Reply
#6

That very strange, I have never heard of this happening before.

Are you using any Ajax?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(01-22-2024, 06:10 AM)InsiteFX Wrote: That very strange, I have never heard of this happening before.

Are you using any Ajax?

No. This is just a regular page load.
Reply
#8

Hi,
just a word to say i'm running into exactly the same problem except for the fact that i'm using php session
my filetr checks if some £_SESSION are set² and always send me back to the login page but if, be it on the login page or disabling the filter in the other pages on all the pages i can see all the vars with a simple print_r
this worked perfectly with ci 4.2, i have several tools working on ci 4.2 and running perfectly with exactly the same filters (well, except for the controllers names of course)
funny thing, if i do exactly the same thing as in my fulter on top of mt controller method it works so too bad with ci 4.4.6-0 the question is:m back to ci 4.2 or to the old way, a custom session helper with a mthod called in every controller methd, sounds a little sad...
have a nice day
Reply




Theme © iAndrew 2016 - Forum software by © MyBB