Jump to content
  • 0

Online Players counter with Javascript ?


Question

Posted

Hello,

I need a Online players counter javascript for my website ?

someone have this ?

Thanks

need help please

need help please

11 answers to this question

Recommended Posts

Posted

Hi v1g0,

This script is based off eAthena's system; it was created by Latheesan, AsuraHosting's Owner.

useronline.php

<?php

#####################################
#  
#    Script By Latheesan - Owner of AsuraHosting
#
#####################################

/* eAthena SQL Database Config */

$host  = "localhost";
$user  = "USERNAME_HERE";
$pass  = "PASSWORD_HERE";
$db    = "DB_NAME_HERE";

#####################################
#  
#    DO NOT EDIT BELOW HERE
#
#####################################

$link = mysql_connect($host, $user, $pass) or die(mysql_error());
@mysql_select_db($db,$link);

$query = "SELECT COUNT(*) as total FROM `char` WHERE online = '1'";
$result = mysql_query($query,$link);
mysql_close($link);

$arr = mysql_fetch_array($result);
$usersonline = $arr["total"];

/* Do NOT Edit Above Here */

?>

index.php (Example of code in use)

<?php 

/* Include Useronline Counter Script */
include("useronline.php");

?>
<html>
<head>
<title>SoulRO Useronline Counter</title>
</head>
<body>
<p>There are currently <?php echo $usersonline; ?> in our server.</p>
</body>
</html>

Hope this helps.

Posted

Thanks for your reply

But i need script : showing online players in real time, without need to refresh web page

i think this script will use javascript.

Can you help me again please ?

Posted

Something like this:

online_user.php:

<?php

header('Content-type:text/plain');

// Configs
$db_host    = "localhost";
$db_name    = "ragnarok";
$db_user    = "ragnarok";
$db_pass    = "ragnarok";
$cache_file = "status.txt";
$cache_time = 60; // seconds.

if ( !file_exists($cache_file) || filemtime($cache_file) + $cache_time < time() ) {
   $db    = new PDO("mysql:host={$db_host};dbname={$db_name}", $db_user, $db_pass );
   $count = $db->query("SELECT COUNT(*) FROM `char` WHERE `online` = '1'")->fetchColumn();
   file_put_contents( $cache_file, $count );
}

readfile($cache_file);
?>

html page:

<div id="online_user"><?php include('online_user.php'); ?></div>

<script type="text/javascript">
// lol IE lol
window.XMLHttpRequest = window.XMLHttpRequest || function() {
   try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch (e) {}
   try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch (e) {}
   try { return new ActiveXObject('Microsoft.XMLHTTP');  } catch (e) {}
   throw new Error('No support for XMLHttpRequest ?');
}

setInterval( function() {
   var req = new XMLHttpRequest();
   req.onreadystatechange = function() {
       if ( this.readyState === 4 && this.status === 200 )
           document.getElementById('online_user').innerHTML = this.responseText; // IE love innerHTML 
   };
   req.open('GET', 'online_user.php', true );
   req.send(null);
}, <?php echo $cache_time * 1000; ?> );
</script>

Posted

Hum need the same script of wowmania.fr

with a file *.js and need to include this script on my website topbar.

I need a script without needing refresh page for actualize players online number.

look wowmania.fr

thanks for interest

Posted

Hum need the same script of wowmania.fr

with a file *.js and need to include this script on my website topbar.

I need a script without needing refresh page for actualize players online number.

look wowmania.fr

thanks for interest

Do you even try my code dude ? :)
Posted

Hi v1g0,

From what I see of KeyWorld's script... it automatically updates the player count every 60secs/1min; so it is a dynamic counter, not static.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...