Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Random Session Destructions
  • If you set 'match_ip' = true in config/session.php, you may encounter random session destructions due to the IP addresses not matching even in localhost.

    After poking around with the Session_Db class, I found out that \Input::ip() and \Input::real_ip() may return either v4 or v6. So if your session IP was initially 127.0.0.1, it may suddenly change to ::1 which will destroy the session.

    I'm not sure if this is a server configuration issue or something else.

    Thoughts anyone?
  • That is weird, depending on the OS and the IP stack used, it has a preference for either IPv4 or IPv6. Usually it's 6 over 4. But whatever the preference, it should always be the same.

    If your client can connect to the webserver on IPv6, I see no reason why it would sometimes choose to connect over IPv4.

    From what I understand, you're working on localhost, so client and server are on the same machine. If you connect using http://localhost/..., it might have to do with the way the hosts file is used.

    btw, "localhost" is an invalid hostname according to the RFCs, should you should avoid using that. Instead, use a dummy domain for your local websites, like "website1.mymachine.local" or "website1.mymachine.dev". Especially on Mac this seems to work better (I heard, don't use one, so I don't have any experience).
  • Hi Harro! Do you also experience this while developing? How do you access your localhost?

    Also, I just removed the matching ip just to make things easier. However, I still experience random session destructions. I played around with the Session_Db class and I found out that the session is being destroyed at https://github.com/fuel/core/blob/1.5/master/classes/session/db.php#L113.

    What are the possible reasons for the session record to be missing as noted by the comment?
  • I never use localhost, or 127.0.0.1. I create hosts file entries like "website.laptopname.local" for every virtualhost I create. These are all aliases for 127.0.0.1. Also, my local apache doesn't listen on IPv6, so I don't have that issue.

    L113 can only happen if you have valid session cookies out there, and you have manually emptied your sessions table. So you have a valid cookie but the session record is missing.

  • Thanks for the tip on the hosts file entries.

    The thing is, I was just navigating around my site then I got L113; didn't touch the sessions table before that happened... 
  • Odd.

    You only get there when your session cookie contains a session id that can't be found (either on session id or previous id).
  • Indeed. I'll do more tests and add updates on it here.
  • Thanks. If there is a bug we need to fix it, sessions are essential to most applications.
  • I had issue on mac with virtual hosts which ends on «.local» (.loc in my issue). It resolves really slowly. That zone uses by avahi service as i think. After that i create only *.dev domains at local net/computer.

Howdy, Stranger!

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

In this Discussion