开发者

Codeigniter tank auth - user gets logged out for no known reason

开发者 https://www.devze.com 2023-01-29 06:22 出处:网络
I am using the codeigniter tank auth library for working with users and it has been working great. Whenever I try to access any controller, the function checks if the user is logged in like this:

I am using the codeigniter tank auth library for working with users and it has been working great. Whenever I try to access any controller, the function checks if the user is logged in like this:

if($this->tank_auth->is_logged_in()) {

If it's logged, I load the model but if not, I do a redirect to the login page. It has been working like this for one month but now I'm extending my application and built some other controllers that uses the same technique but the files are located in other folder. The previous working application still works great but in this app from the new folder (it's basically a new module for that application, uses the same login page but redirects differently according to user selection of the module) I can login correctly, I can make a any request to the controller with no problems but at some point, it tells me the user is not logged in. It's not the session expired or something, it's like I'm making one request now, extending my session and the next at 3 seconds interval gets the user logged out...I've done nothing different with my new controllers, but still, after a while, sometimes it takes 5 minutes, sometimes 15 minutes, it logs out...I don't know why, is something messing with my session ? I don't use session for anything else...

Anybody knows what this is about ? Or any suggestion ? I can give further details if requested.

Thank you very much.

EDIT: The new module consists in more controllers in the same Codeigniter instalation, it works with the same CI config, same tank auth library and the functions are copied to the main requests controller like this:

class Requests extends Controller
{
    function __construct()

    {
        parent::__construct();
开发者_JS百科
        $this->load->helper(array('form', 'url'));
        $this->load->helper('date');
        $this->load->library('form_validation');
        $this->load->library('tank_auth');
    }

..............
more functions
..............

    function getServices() { /// One of the functions that the new module uses
            if (!$this->tank_auth->is_logged_in()) {
                return;
            } else {
                $this->load->model('requests/getServices');
                $data['tid'] = $_POST['tid'];
                $this->getServices->showData($data);
            }

        }


I suspect that the delay in the cookie disappearing has something to do with $config['time_to_update'] (default is 300 seconds).

Cookies are only update (re-set) every 5 minutes if no session variables are changed. So, it might be that the cookie becomes invalid from the point of view of the new part of the application, but the Session class doesn't realize it until the 300 seconds passes, at which point it is cleared and the user becomes logged out.

Can you provide more detail on where to new code is. Is it in the same CodeIgniter installation? etc.


I was messing around with my session in one image upload function that I used in another app. I have erased those session lines and now it works as it should be. The session code was PHP native $_SESSION code in case anyone is wondering.

Thanks.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号