Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Session not on every page? Keeps logging me out?
  • Okay on the main homepage, no matter how many times I refresh after logging in, it keeps me logged in and shows all my user info and whatnot.
    However, when I navigate to a different page whether it is the news or any other page... it logs me out and says no one is logged in...

    How do I keep the session going past the homepage? I don't understand what's going on and why it's not keeping that session going...
    I set a userid session and then it... dies after navigating away from the homepage.
  • Most obvious culprit is time.

    Sessions are maintained using a cookie containing the session id. Cookies contain an expiry timestamp defined in GMT. This means that your webserver will take time(), add the session expiry timeout to it, and converts it from local time to GMT before sending the cookie out.

    The mechanism goes very wrong if:
    - the timezone setting of your server is wrong
    - the timezone setting of your application doesn't match the server
    - the time of the server is not correct
    - the time of the PC running the browser is not correct

    Given the fact that the default session cookie timeout is two hours, you get this when it's off somewhere by more then two yours.

    For example, if your server is in PST (which is GMT-8), and you're config setting says UTC, all  GMT time calculations made by your application are off by 8 hours.
  • Ok... well I'm on version 1.4 so there is no default timezone anymore. Could that be messing with anything?
    I'm confused on what files to exactly check. I have America/New York as my default timezone and another file says UTC.. like I'm just confused.
    My WAMP server is in perfect EST timezone. I just inserted a thing set to CURRENT_TIMESTAMP and it has the correct date and time.
  • Absolutely. As documented and mentioned in the release notes, you HAVE to set the correct timezone in the config. And it MUST match the timezone of your service.

    If your server is on America/New York, and you tell Fuel it's in UTC, GMT time calculation will be off by 5 hours, causing the session to fail.

    So note it's not about time(), which is the local time, but about the calculation of GMT time.
  • So I guess my last question is.. what do I change UTC to? Is GMT the same as EST? Or do I just turn it to EST? I'm not really entirely sure what time UTC is in and what thing I would put in for America/New York unless I put THAT there as well??
  • No, GMT = Greenwich Mean Time, which unless you're in the UK is the wrong timezone for you. UTC is equal to GMT, unless daylight savings is in effect, in which case it's GMT+1.

    It should be the same as defined on your server, which should be the same as in your php.ini (the date.timezone parameter), which should be the same as your config.php timezone setting.

    In your case, they should all be "America/New York" if that is your local timezone.
  • Ok I have BOTH set to EST... still logging me out. It keeps me logged in on the home page no matter how many times I refresh, but as soon as I go to a different page, it logs me out...

    Do you maybe have to initiate some sort of Session on every single page to keep it going? Like I click on News and it shows me logged in, but if I refresh once, it logs me out. And keeps me logged out even when I go back to the homepage.
  • So it had nothing to do with the time.
    It was because I was creating another instance of Auth and I guess it was overriding it or something. And I was getting the userid from the session in the base controller AND news controller. So now I just made a protected static variable called $userid in the base controller so i can access it from the other controllers using parent::$userid :)
    Thanks though!!
  • Good to hear you've got it fixed!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion