Log in

View Full Version : Resolved online users list



auriaks
11-07-2009, 04:02 AM
I want to create list of online users with php... I have an idea to create mysql variable which saves numbers 0 or 1. when user logs i it will be rewritten to 1, when logs out to 0. And my list will show all users, who have 1 in their wariables.

Maybe someone have better idea? Or can write me a script of my idea? Because i do too much mistakes. THANKS A LOT :)

auriaks
11-07-2009, 10:55 AM
too difficult?

Schmoopy
11-07-2009, 12:51 PM
The way you proposed sounds like it should work and I can't see any other way of doing it, maybe using a text file... But just changing a variable from 0 to 1 should do the trick and it shouldn't be too hard to implement.

bluewalrus
11-07-2009, 03:32 PM
That's assuming your users always log out though. If they don't and just exit the browser then that number will begin to become high quickly. You could make up an activity table that sets their log in time and there activity time. If their activity time goes past some amount of time make their online number back to 0.

auriaks
11-08-2009, 10:16 AM
good idea to use time... thanks. maybe u can tell me some links with lessons of that?

auriaks
11-08-2009, 10:19 AM
session: (some lines)

session_start();
$_SESSION['nick'] = $_POST['nick'];
$_SESSION['password'] = md5($_POST['password']);
$_SESSION['authID'] = $r['id'];

online script:


<?php

include('db_conn.php');

session_start(); // begin session

if(isset($_SESSION['authID'])) {
$q = mysql_query("SELECT * FROM reg_users WHERE Nick='$_SESSION[nick]'") or die(mysql_error());
$r = mysql_fetch_array( $q ) or die(mysql_error());
//atsiras
$date = date("Y-m-d");
$count1 = '1';
$nick = $_SESSION['nick'];
mysql_query("UPDATE reg_users SET date = '$date' WHERE name = '$nick'");
mysql_query("UPDATE reg_users SET count = '$count1' WHERE name = '$nick'");
//atsiras-pabaiga

} else { }
if($_GET['act'] == 'logout') {
echo '<center><font color="Green">You\'re successfully logged out.</font></center>';
session_unset();
session_destroy(); // remove the entire session
include('db_conn.php');
$count2 = '0';
mysql_query("UPDATE reg_users SET count = '$count2' WHERE name = '$nick'");
}
?>


My number and date doesnt changes... maybe see where?? and how to add time there? THANKS :)

fg123
11-08-2009, 09:13 PM
Time? Just like date:


<?php
$i=date("Y-m-d H:i:s");//the default for php/mysql
?>




My number and date doesnt changes... maybe see where?? and how to add time there? THANKS :)

Are you sure the mysql field format is date?

auriaks
11-09-2009, 01:08 AM
How i can use this time into my script? I thought about command which gives automatically (every 5 minutes) looks if user is logged...