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="Heaplink" data-source="post: 227059" data-attributes="member: 8966"><p>A HTML file cannot be interpreted as PHP (unless you use mod_rewrite - but is a very unsecure and bad way to do). Do something like this instead:</p><p> </p><p>[PHP]<?php</p><p>require_once 'simple_html_dom.php';</p><p>// 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 thank using 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>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($ret[0]));</p><p>}[/PHP]</p><p> </p><p>and in another file you can do this:</p><p> </p><p>[PHP]<?php</p><p> require_once 'YOUR_FILE.php';</p><p>?></p><p><html></p><p><head></p><p> <title>Better</title></p><p></head></p><p><body></p><p> <p>There are <b><?=getOnlineUsers()?></b> users online, right now!</p></p><p></body></p><p></html>[/PHP]</p><p> </p><p>A rule of thumb in PHP is require/include and validate at the top of the page if you're going to have markup with your php. Then mostly to condition checking and echoing in the markup as above <span style="font-family: 'courier new'"><?=?></span> is the same as <span style="font-family: 'courier new'"><?</span> echo <span style="font-family: 'courier new'">?></span></p><p> </p><p>Note: <span style="font-family: 'courier new'"><?</span> and <span style="font-family: 'courier new'"><?=</span> are short tags. These has to be enabled in php.ini in order for them to work (by default in PHP >=5.1 it is enabled - might also be in older versions of PHP.)</p></blockquote><p></p>
[QUOTE="Heaplink, post: 227059, member: 8966"] A HTML file cannot be interpreted as PHP (unless you use mod_rewrite - but is a very unsecure and bad way to do). Do something like this instead: [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 thank using 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($ret[0])); }[/PHP] and in another file you can do this: [PHP]<?php require_once 'YOUR_FILE.php'; ?> <html> <head> <title>Better</title> </head> <body> <p>There are <b><?=getOnlineUsers()?></b> users online, right now!</p> </body> </html>[/PHP] A rule of thumb in PHP is require/include and validate at the top of the page if you're going to have markup with your php. Then mostly to condition checking and echoing in the markup as above [FONT=courier new]<?=?>[/FONT] is the same as [FONT=courier new]<?[/FONT] echo [FONT=courier new]?>[/FONT] Note: [FONT=courier new]<?[/FONT] and [FONT=courier new]<?=[/FONT] are short tags. These has to be enabled in php.ini in order for them to work (by default in PHP >=5.1 it is enabled - might also be in older versions of PHP.) [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Releases
Non-local Online Users Script -- Evaluate my Code
Top