v1g0 Posted June 18, 2012 Posted June 18, 2012 Hello, I need a Online players counter javascript for my website ? someone have this ? Thanks need help please need help please
Asura Posted June 19, 2012 Posted June 19, 2012 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.
v1g0 Posted June 19, 2012 Author Posted June 19, 2012 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 ?
JayPee Posted June 20, 2012 Posted June 20, 2012 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
v1g0 Posted June 20, 2012 Author Posted June 20, 2012 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
KeyWorld Posted June 20, 2012 Posted June 20, 2012 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>
v1g0 Posted June 20, 2012 Author Posted June 20, 2012 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
KeyWorld Posted June 20, 2012 Posted June 20, 2012 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 ?
v1g0 Posted June 20, 2012 Author Posted June 20, 2012 yes, but i need refresh page for update online players it isn't that i asked. thanks for your interest
Asura Posted June 20, 2012 Posted June 20, 2012 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.
v1g0 Posted June 20, 2012 Author Posted June 20, 2012 sorry , i have read fastly, Thanks i will testing this.
Boy Posted October 17, 2012 Posted October 17, 2012 Hi Asura Where can i put useronline.php and index.php?
Question
v1g0
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