I have made a server – client app in android with php and mysql. When any new user registers and clicks on submit button then his/her information goes to php and gets stored in mysql database that is on the internet.
And then i have get that list of peoples in listview who are registered before in my app and in listview i can see all that people but now i want to add a functionality that can check who is online right now in my app. I will make two buttons ONLINE and OFFLINE. When i press the ONLINE buttons only those people should be display who are using this app right now.
I have also search this in web but i dint find any proper result, so please anybody who have made this before please give me some idea or link of tutorial regarding this.
Thank you for your time.
In your DB, add a field called (last_login as DateTime). This field is updated each time the user logins to the application, and start a new session. Use a query similar to the below.
UPDATE tbl_users SET last_login=NOW() WHERE ID_FIELD = $USER_IDWhenever a user clicks the (Who is Online) button, a PHP script is called that queries all the user where the last_login field contains a value for example less than 3 hours.
The query you can use
SELECT * FROM tbl_users WHERE TIMESTAMPDIFF(HOUR,last_login,NOW()) <=3