Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Session Problem
  • I build an application. In the application i need session_id when the user came for the first time.
    So i made a common controller and put one of the static method from my class to write session_id to database.. But It didn't work. When user came first it record 0, then second time it catchs the users session id. I'm using DB session. It works fine.
    But Session::key('session_id') doesnt work in common controller before's when the user came first. I've read some bugs that Harro says it'll be gone on 1.2.1. I updated my core folder with 1.2.1 but nothing change..
    And also i saw that if there is nothing to record to session. Session won't create.. So i even put Session::set('time', time()) to create..
    But write after this line i tried to get to key(Session::key('session_id'). it doesn't work. And also i checked that when i set something to session i can't access right after.. Can you help me? Where am i wrong? I can't get session_id..
    PS: Session_auto_load is true. Also i set my config file for auto load session.
  • Always a difficult subject, because you're working in a stateless environment, so what is the definition of "online"? I don't think it's a good idea to modify the session behaviour for what. For one project I have extended the users table with a 'last_seen' column, which gets updated in my base controller, and which allows me to run a query on the users table. On high volume sites you don't want to do that, for those I use an array in (memcached) cache which holds entries with user information and last seen date. I update that in a shutdown event (which also does the expiry of entries over a threshold). And I have a helper class that retrieves a list of online users based on a cut-off time (for example last 15 minutes).
  • Session updates happen in a shutdown event. In case of a new session, this is where the session is created, so you will not have a session_id before. The session_id is an internal variable, so you shouldn't use that anyway, as the way the Session class works internally may change without notice.
  • Thank you for your response. Actually The problem begins here; I'm trying to control,the user is online in last 5 min or not ? To understand it, I put a field that is "user_id" in sessions table. When i need to check i'm just searching user_id and checking last updated time.. But to set user_id i need to fetch user session_id to write him/her user_id. If it's not okay to use session_id how can detect user is online or not?

Howdy, Stranger!

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

In this Discussion