PHP - User online script
-
How do I check whether the user is online or not? How do I show online users in php? Can anybody help? It's urgent please.
-
Answer:
// 1. $ip = $_SERVER["REMOTE_ADDR"]; $min = 15; $time = time(); $timeout = $time - ($min * 60); // 2. mysql_query("DELETE FROM online WHERE ip = '$ip' OR timestamp < $timeout"); mysql_query("INSERT INTO online(ip,timestamp) VALUES('$ip', $time)"); // 3. $sql = mysql_query("SELECT COUNT(0) FROM online"); $online = mysql_fetch_array($sql); $online = $online[0];
Gaurav Srivastava at Stack Overflow Visit the source
Other answers
Build a table where you can update a timestamp when a logged in user doing some activity. You know how large is your session lifetime value so when an activity happens, you'll need to check 'dead' sessions (delete those rows) and display how many 'active' sessions you've got. Note: this won't be an exact value
fabrik
Related Q & A:
- How To Detect Online Facebook User?Best solution by Stack Overflow
- How to convert Oracle script to MySQL script?Best solution by Stack Overflow
- How can I make Private Messages in Drupal 7 with user user pictures like in Facebook?Best solution by Drupal Answers
- How to check on all the permissions granted to a user and apply the same permissions to another user?Best solution by Stack Overflow
- How to start creating a php script, that will be installed on many servers?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.