Jump to content
  • 0

Online Players counter with Javascript ?


v1g0

Question


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  34
  • Reputation:   1
  • Joined:  12/06/11
  • Last Seen:  

Hello,

I need a Online players counter javascript for my website ?

someone have this ?

Thanks

need help please

need help please

Link to comment
Share on other sites

11 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  707
  • Reputation:   168
  • Joined:  01/26/12
  • Last Seen:  

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.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  34
  • Reputation:   1
  • Joined:  12/06/11
  • Last Seen:  

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 ?

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  47
  • Topics Per Day:  0.01
  • Content Count:  633
  • Reputation:   78
  • Joined:  11/14/11
  • Last Seen:  

use the xml version of the server status then fetch the xml contents using javascript ajax i recommend that you use jquery library since its easy to use ajax in jquery.

See our patcher server status.

http://www.agonyro.net/patcher/server_status.html

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  34
  • Reputation:   1
  • Joined:  12/06/11
  • Last Seen:  

Hello Jaypee

can you show an example of script java.

I have found an example what i am searching : www.wowmania.fr

It's a french private wow server.

http://wowmania.fr/scripts/stats.js

.i would like the same for my ragnarok server

thanks

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

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>

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  34
  • Reputation:   1
  • Joined:  12/06/11
  • Last Seen:  

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

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  379
  • Reputation:   304
  • Joined:  11/10/11
  • Last Seen:  

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 ? :)
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  34
  • Reputation:   1
  • Joined:  12/06/11
  • Last Seen:  

yes, but i need refresh page for update online players

it isn't that i asked.

thanks for your interest

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.00
  • Content Count:  707
  • Reputation:   168
  • Joined:  01/26/12
  • Last Seen:  

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.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  34
  • Reputation:   1
  • Joined:  12/06/11
  • Last Seen:  

sorry , i have read fastly,

Thanks i will testing this.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  134
  • Reputation:   4
  • Joined:  09/28/12
  • Last Seen:  

Hi Asura

Where can i put useronline.php and index.php?

Link to comment
Share on other sites

×
×
  • Create New...