Using sessions with database.. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Using sessions with database.. (/showthread.php?tid=57056) |
Using sessions with database.. - El Forum - 02-11-2013 [eluser]GonzaFY[/eluser] I am here with some questions again.. Sorry for that but this is the best forum to question lol . Sorry for my english. Well I finally understood how works the sessions with database.. If I am not wrong, CI makes a session id each time anyone visit the page and save that into database and in a cookie. Every time that you decide, it refresh and check if the cookie has the same id as the database, if it isn't the session is destroyed. Then I made the table into my mysql, now I have two tables: Members (to check the login and store the user's data) and CI_Sessions (to check the sessions and store the user's data that I already called when a user log). I wanna know if I am doing something wrong because it seems too easy to use.. In my code, when a user log in, it check if the username and the password is the same with some row into the database, if this is true then I get all the data from the database (name, surname, address, level, etc) and store this in sessions (CI_Sessions database). After I call to those sessions to get information about the user.. ($this->session->userdata('address') Is that ok? And another question, How can I check if a third user is online? I thought having another column in my "Members" table called "Status" and then when the user is logged I make a call to sessions and will be true, if he is online change "Status" to Connected. All is fine now but I don't know how change "Status" it to "offline" if his session is destroyed because expired.. Anyone have idea? Is this the best way to do that? EDIT: Another way will be using a php file that refresh every X minits and check the last activity of a user and if it reached more than 5 minits (for example) it return "OFFLINE" but I don't understand the column "Last_Activity".. It return "1360644145" .. What is that? Ok the solution is: Code: public function Estado($usuario) Sorry for my english =/! Using sessions with database.. - El Forum - 02-12-2013 [eluser]InsiteFX[/eluser] To update a user online status you would need to use javascript timer events. For the database you would need to create a user_online table and store the information in it. Using sessions with database.. - El Forum - 02-12-2013 [eluser]GonzaFY[/eluser] [quote author="InsiteFX" date="1360678038"]To update a user online status you would need to use javascript timer events. For the database you would need to create a user_online table and store the information in it. [/quote] Do you mean a third database? And why can't I store the information into ci_sessions? I was thinking and I deduced I need do something like the facebook chat, if the user has the window opened then he is connected, if he close the browser he become off... But I don't want destroy the session when he close. Thank Then now I am trying to use the sess_expire_on_close to set off a user (but not expire the session) but when I search into the core I found only that: $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); I wanna make when sess_expire_on_close is called make "Status" to 0 but I don't understand how do that.. |