[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)
{
// We get the LAST session of the $usuario
$funcion = $this->CI->db
->like('user_data', $usuario)
->limit(1)
->order_by('last_activity', 'desc')
->get('ci_sessions');
// If there is one...
if($funcion->num_rows() > 0)
{
$cuenta = $funcion->row()->last_activity;
$now = time();
// We check if he is active..
if($cuenta + 100 > $now)
{
echo 'ONLINE';
}
else
{
echo 'OFFLINE';
}
}
else
{
echo 'OFFLINE';
}
}
Sorry for my english =/!