|
|
|
|
![]() ![]() |
Feb 4 2008, 09:55 AM
Post
#1
|
|
|
Oh come on Mrs. B! Group: Members Posts: 648 Joined: 6-June 07 From: Tasmania, Australia Member No.: 22,422 |
Sorry for being a pain and not knowing much PHP, I'm not that brilliant at it.
Anyway, can anyone help me with this little code? <?php $online = file_get_contents("http://www.habbo.com.au/habbo_count_xml.action") or die(" 0"); $onlinee = trim(strip_tags($online)); echo $online; ?> All it does is show how many people are online on Habbo Australia. It works, except when Habbo is down (it is now because the servers carked it) it gives me this. Warning: file_get_contents(http://www.habbo.com.au/habbo_count_xml.action) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable in /home/habfront/public_html/templates/habbo_front_1/index.php on line 132 It still shows the 0 for when it dies except how do I get it not to show the error? There's also another problem with it, well I'm using Joomla and when Habbo is down, along with the error, it also stops the component and modules and that from showing which is really annoying. So how do I make it so it doesn't show the error and just shows the 0 and the whole site will work properly? Once again, I'm a PHP nub! |
|
|
|
Feb 4 2008, 10:50 AM
Post
#2
|
|
|
Premium Member Group: [HOSTED] Posts: 367 Joined: 16-February 06 From: Kolkata, India Member No.: 11,322 |
Use the error_reporting() function to set the error_reporting directive as follows:-
Disable: error_reporting(0); Enable: error_reporting(1); Use this before the block you want to disable error reporting. You should however turn it back on, otherwise all errors will go undetected. CODE <?php error_reporting(0); // Disable Error Reporting $online = file_get_contents("http://www.habbo.com.au/habbo_count_xml.action") or die(" 0"); error_reporting(1); // Turn it back on $onlinee = trim(strip_tags($online)); echo $online; ?> |
|
|
|
Feb 4 2008, 12:19 PM
Post
#3
|
|
|
Way Out Of Control - You need a life :) Group: [MODERATOR] Posts: 1,969 Joined: 16-August 05 Member No.: 7,896 |
@turbopowerdmaxsteel : great idea, disabling and re-enabling error reporting !
@Sten : I touched your topic title in order to make it more specific, feel free to correct it if I misunderstood it. Yordan |
|
|
|
Feb 5 2008, 06:53 AM
Post
#4
|
|
|
Oh come on Mrs. B! Group: Members Posts: 648 Joined: 6-June 07 From: Tasmania, Australia Member No.: 22,422 |
That works, it doesn't show the error!
Except... it's still stopping the modules and component and the Joomla header and everything else after it from loading. Which basically means that when Habbo is down, my site is down which is quite annoying. I know other fansites use the same code and it doesn't do it for them, but they aren't using a CMS, the most they use is Cutenews for their news. Anyone know how to make it load other things? PHP (well the Joomla things) and anything (content and images etc) after the code doesn't show. |
|
|
|
Feb 8 2008, 01:20 AM
Post
#5
|
|
|
Super Member Group: [HOSTED] Posts: 740 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 |
That works, it doesn't show the error! Except... it's still stopping the modules and component and the Joomla header and everything else after it from loading. Which basically means that when Habbo is down, my site is down which is quite annoying. I know other fansites use the same code and it doesn't do it for them, but they aren't using a CMS, the most they use is Cutenews for their news. Anyone know how to make it load other things? PHP (well the Joomla things) and anything (content and images etc) after the code doesn't show. I guess that it stops because you use the die() function, the file_get_contents() function returns a string with the contents of the file on success and FALSE on failure, so, instead try the following: CODE <?php error_reporting(0); // Disable Error Reporting $online = file_get_contents("http://www.habbo.com.au/habbo_count_xml.action"); error_reporting(1); // Turn it back on if ($online) { $onlinee = trim(strip_tags($online)); echo $onlinee; } ?> Best regards, |
|
|
|
Feb 8 2008, 01:42 AM
Post
#6
|
|
|
Oh come on Mrs. B! Group: Members Posts: 648 Joined: 6-June 07 From: Tasmania, Australia Member No.: 22,422 |
Thanks, that works now!
I added CODE else { echo " 0"; } to it so that it shows 0 if it can't find it! |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 22nd August 2008 - 05:11 AM |