Jump to content
xisto Community
Sign in to follow this  
iGuest

Who's online?

Recommended Posts

Simple 'User Online' script


If you use this, Please link back to my site at
http://forums.xisto.com/no_longer_exists/ :)

/* First create/edit the user the table with at least these fields: */CREATE TABLE user (  `id` int(11) NOT NULL auto_increment,   'username' varchar(40) NOT NULL,    'last_login' varchar(100) NOT NULL,    PRIMARY KEY (last_login), ); 
<?///////////////////////* next write the script to retrieve online userscan be adjusted to appear anywhere on any page by copying the bit between //copy// and //end copy// to anywhere you wish. Without copying ti will show up when the url is file.php?page=usersonline assuming a name of file.php for this file */$page = $_GET['page'];if($page == usersonline) {/////COPY//////$useronlinetable = user;$server = "localhost"; $db_user = "username"; $db_pass = "password"; $database = "database"; /// INSERT basic info for db connectmysql_connect($server, $db_user, $db_pass); $timeout = 120;/* ADJUST how long after a user has refreshed a page that user is said to be offline. Currently 2 minutes. Value in seconds. */      $date=time();$date = $date+18000;$date = $date - $timeout;$sql_useron = mysql_query("SELECT * FROM users WHERE last_login > FROM_UNIXTIME($date)");$users_row = mysql_num_rows($sql_useron);if ($users_row == 1) {$userp = "user";$areis = "is";} else {$userp = "users";$areis = "are";}print "There $areis $users_row $userp currently online<br><br>";/* the following will display on page*/while($row=mysql_fetch_array($sql_useron)) {print $row["username"].'<br>';}/* end display on page*//////// END COPY/////}?>


Final Bit...

<?/*somewhere on the page you need to update the last login on page refreshmy website has this all linked to an IM system that ive posted on here - and you can adapt it however you want*/if (isset($_SESSION['username'])) {      $date=time();$date = $date+18000;	$sql = mysql_query("UPDATE users SET last_login=FROM_UNIXTIME($date) WHERE id='$userid'");}?>

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.