Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Q&A
[Request] Client Online Counter
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Chuckie_" data-source="post: 461646" data-attributes="member: 86709"><p>Make a PHP page that will return the amount of online users.</p><p>[CODE=php]<?php</p><p>$connection = new mysqli("db_host", "db_user", "db_password", "db_name");</p><p></p><p>$sql = "SELECT COUNT(*) FROM users WHERE online='1'";</p><p></p><p>$result = $connection->query($sql);</p><p></p><p>echo $result;</p><p></p><p>$connection->close();[/CODE]</p><p></p><p>Save it as online.php or something in your pages folder, so that you can get the online count by going to the <a href="https://yourhotel.com/online" target="_blank">https://yourhotel.com/online</a> url.</p><p></p><p>Then add a script in your client.php that fetches the online amount every x seconds. In this example every 10 seconds (the fetchInterval variable).</p><p>[CODE=javascript]<script></p><p>const fetchInterval = 30000 // Time between each fetch query 30000/1000 = 30 seconds.</p><p></p><p>let getOnline = () => {</p><p> fetch('/online').then(res => {</p><p> document.querySelector("#online-element").innerHTML(res);</p><p> })</p><p>}</p><p></p><p>setInterval(getOnline, fetchInterval);</p><p></script>[/CODE]</p><p></p><p>This assumes that you will be having some kind of HTML element with the id [ICODE]online-element[/ICODE], where it will output the current online amount. You can rip it off someone else's client page or design your own, I won't spoonfeed you that much.</p><p></p><p>Please note, this should be considered pseudo code, as I haven't done PHP and vanilla JS in ages.</p><p></p><p>Good luck <img src="/styles/default/xenforo/smilies/emojione/smile.png" class="smilie" loading="lazy" alt=":)" title="Smile :)" data-shortname=":)" /></p></blockquote><p></p>
[QUOTE="Chuckie_, post: 461646, member: 86709"] Make a PHP page that will return the amount of online users. [CODE=php]<?php $connection = new mysqli("db_host", "db_user", "db_password", "db_name"); $sql = "SELECT COUNT(*) FROM users WHERE online='1'"; $result = $connection->query($sql); echo $result; $connection->close();[/CODE] Save it as online.php or something in your pages folder, so that you can get the online count by going to the [URL]https://yourhotel.com/online[/URL] url. Then add a script in your client.php that fetches the online amount every x seconds. In this example every 10 seconds (the fetchInterval variable). [CODE=javascript]<script> const fetchInterval = 30000 // Time between each fetch query 30000/1000 = 30 seconds. let getOnline = () => { fetch('/online').then(res => { document.querySelector("#online-element").innerHTML(res); }) } setInterval(getOnline, fetchInterval); </script>[/CODE] This assumes that you will be having some kind of HTML element with the id [ICODE]online-element[/ICODE], where it will output the current online amount. You can rip it off someone else's client page or design your own, I won't spoonfeed you that much. Please note, this should be considered pseudo code, as I haven't done PHP and vanilla JS in ages. Good luck :) [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Q&A
[Request] Client Online Counter
Top