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 Releases
Non-local Online Users Script -- Evaluate my Code
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="Brackson" data-source="post: 226990" data-attributes="member: 34747"><p><span style="font-size: 12px"><span style="font-family: 'verdana'">Hello DevBest.</span></span></p><p> </p><p><span style="font-size: 13px"><span style="font-family: 'Verdana'"><span style="color: #333333">This is probably one of my first PHP scripts that I actually tried to make and understand, and I was wondering what you guys thought of it and if it could be optimized or not.</span></span></span></p><p> </p><p><span style="font-size: 13px"><span style="font-family: 'Verdana'"><span style="color: #333333">What this script does is reads the online count of an index page of a specific retro. I understand that not all retros have their online count in the same div, and I know that this script has to be personalized for every website that you use it on.</span></span></span></p><p> </p><p><span style="font-size: 13px"><span style="font-family: 'Verdana'"><span style="color: #333333">Also, please excuse the thread title; it's kind of hard to think of a name for something like this.</span></span></span></p><p> </p><p><span style="font-size: 13px"><span style="font-family: 'Verdana'"><span style="color: #333333">Here it is!</span></span></span></p><p> </p><p><span style="font-family: 'verdana'">Save this as YOUR_FILE.PHP.</span></p><p>[PHP]</p><p><?php</p><p> require_once 'simple_html_dom.php';</p><p> // Download here http://sourceforge.net/projects/simplehtmldom/files/simple_html_dom.php/download</p><p> // It parses the HTML so we can get the div from the source easier than regular expression.</p><p> </p><p> /**</p><p> * Gets number of online users</p><p> * @return int The number of users online</p><p> **/</p><p> </p><p> function getOnlineUsers() {</p><p> $url = "http://xenon.pw/?novote";</p><p> $html = file_get_html($url);</p><p> $onlineUsers = $html->find('div[id="online"]');</p><p> return intval(strip_tags($onlineUsers[0]));</p><p>}</p><p>[/PHP]</p><p> </p><p><span style="font-family: 'verdana'">and save this file something else.</span></p><p> </p><p>[PHP]</p><p><?php</p><p> require_once 'YOUR_FILE.php';</p><p>?></p><p> </p><p><html></p><p><head></p><p> <title>Better script (by Heaplink)</title</p><p></head></p><p> </p><p><body></p><p> <p>There are <b><?=getOnlineUsers() ?></b> users online, irght now!</p></p><p></body></p><p></html></p><p>[/PHP]</p><p><em><span style="font-size: 9px"><span style="font-family: 'verdana'">*Special thanks to Heaplink for these two scripts, which are much more efficient than my first. Compare <a href="http://pastebin.com/m5ZbdsUU" target="_blank">here</a>.</span></span></em></p><p> </p><p><span style="font-size: 13px"><span style="font-family: 'Verdana'"><span style="color: #333333">I used Xenon because I'm a staff member on it, and it has it's online count on it's index page (which makes it a </span></span></span><em><span style="font-size: 13px"><span style="font-family: 'Verdana'"><span style="color: #333333">lot </span></span></span></em><span style="font-size: 13px"><span style="font-family: 'Verdana'"><span style="color: #333333">easier). I figured that this script would be good for fansites and such, since it echo's the code as plain text, and you can style it how ever you want to.</span></span></span></p><p> </p><p><span style="font-size: 13px"><span style="font-family: 'Verdana'"><span style="color: #333333">What do you guys think?</span></span></span></p><p> </p><p><span style="font-size: 9px"><span style="font-family: 'Verdana'"><span style="color: #333333"><em>This has not been released yet. Please do not release this.</em></span></span></span></p></blockquote><p></p>
[QUOTE="Brackson, post: 226990, member: 34747"] [SIZE=3][FONT=verdana]Hello DevBest.[/FONT][/SIZE] [SIZE=13px][FONT=Verdana][COLOR=#333333]This is probably one of my first PHP scripts that I actually tried to make and understand, and I was wondering what you guys thought of it and if it could be optimized or not.[/COLOR][/FONT][/SIZE] [SIZE=13px][FONT=Verdana][COLOR=#333333]What this script does is reads the online count of an index page of a specific retro. I understand that not all retros have their online count in the same div, and I know that this script has to be personalized for every website that you use it on.[/COLOR][/FONT][/SIZE] [SIZE=13px][FONT=Verdana][COLOR=#333333]Also, please excuse the thread title; it's kind of hard to think of a name for something like this.[/COLOR][/FONT][/SIZE] [SIZE=13px][FONT=Verdana][COLOR=#333333]Here it is![/COLOR][/FONT][/SIZE] [FONT=verdana]Save this as YOUR_FILE.PHP.[/FONT] [PHP] <?php require_once 'simple_html_dom.php'; // Download here http://sourceforge.net/projects/simplehtmldom/files/simple_html_dom.php/download // It parses the HTML so we can get the div from the source easier than regular expression. /** * Gets number of online users * @return int The number of users online **/ function getOnlineUsers() { $url = "http://xenon.pw/?novote"; $html = file_get_html($url); $onlineUsers = $html->find('div[id="online"]'); return intval(strip_tags($onlineUsers[0])); } [/PHP] [FONT=verdana]and save this file something else.[/FONT] [PHP] <?php require_once 'YOUR_FILE.php'; ?> <html> <head> <title>Better script (by Heaplink)</title </head> <body> <p>There are <b><?=getOnlineUsers() ?></b> users online, irght now!</p> </body> </html> [/PHP] [I][SIZE=1][FONT=verdana]*Special thanks to Heaplink for these two scripts, which are much more efficient than my first. Compare [URL='http://pastebin.com/m5ZbdsUU']here[/URL].[/FONT][/SIZE][/I] [SIZE=13px][FONT=Verdana][COLOR=#333333]I used Xenon because I'm a staff member on it, and it has it's online count on it's index page (which makes it a [/COLOR][/FONT][/SIZE][I][SIZE=13px][FONT=Verdana][COLOR=#333333]lot [/COLOR][/FONT][/SIZE][/I][SIZE=13px][FONT=Verdana][COLOR=#333333]easier). I figured that this script would be good for fansites and such, since it echo's the code as plain text, and you can style it how ever you want to.[/COLOR][/FONT][/SIZE] [SIZE=13px][FONT=Verdana][COLOR=#333333]What do you guys think?[/COLOR][/FONT][/SIZE] [SIZE=1][FONT=Verdana][COLOR=#333333][I]This has not been released yet. Please do not release this.[/I][/COLOR][/FONT][/SIZE] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Releases
Non-local Online Users Script -- Evaluate my Code
Top