Help this php code

This is guide mostly for website tools and code, for example CMS or registration scripts.
There can also be tools.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

Help this php code

Postby kondeddie on Tue Jan 08, 2013 1:05 am

Server Status: <?php $open = @fsockopen('localhost', '29200', $ERRNO, $ERRSTR, .1);
if(!$open) {
echo '<b><font color=green>Online</font></b>';
} else {
echo '<b><font color=red>Offline</font></b>';
} ?><br>

I am using this code but it does not update the page saying this is online or offline..
kondeddie
Jelly Bean
Jelly Bean
 
Posts: 23
Joined: Wed Dec 26, 2012 10:12 pm

Re: Help this php code

Postby xadet3 on Tue Jan 08, 2013 11:50 am

Remove the @ and see what errors you get (the port should also be an integer, not a string).
xadet3
Pero pero
Pero pero
 
Posts: 727
Joined: Tue Jan 08, 2008 11:51 pm
Location: Norwich, England.

Re: Help this php code

Postby kondeddie on Tue Jan 08, 2013 6:15 pm

Server Status: <? Php $ open = fsockopen ('localhost', 29200, $ ERRNO, $ errstr, .1);
if (! $ open) {
echo '<b> <font color=green> Online </ font> </ b>';
Else {}
echo '<b> <font color=red> Offline </ font> </ b>';
}?> <br>

as you said and let @ removed the entire door and this error occurred:

Warning: fsockopen () [function.fsockopen]: unable to connect to localhost: 29200 (A connection attempt failed because the connected NCO properly respond after a perķodo time or established conexćo failed because connected host NCO replied.) In C: \ Program Files (x86) \ EasyPHP 2.0b1 \ www \ index.php on line 80
kondeddie
Jelly Bean
Jelly Bean
 
Posts: 23
Joined: Wed Dec 26, 2012 10:12 pm

Re: Help this php code

Postby xadet3 on Tue Jan 08, 2013 6:21 pm

Does it output that error even if the server is up?
xadet3
Pero pero
Pero pero
 
Posts: 727
Joined: Tue Jan 08, 2008 11:51 pm
Location: Norwich, England.

Re: Help this php code

Postby Circa on Tue Jan 08, 2013 8:13 pm

  1. Server Status: <? Php $ open = fsockopen ('localhost', 29200, $ ERRNO, $ errstr, .1);
  2. if (! $ open) {
  3. echo '<b> <font color=green> Online </ font> </ b>';
  4. Else {}
  5. echo '<b> <font color=red> Offline </ font> </ b>';
  6. }?> <br>


i don't know php, that else part looks wrong :P

  1. Server Status: <? Php $ open = fsockopen ('localhost', 29200, $ ERRNO, $ errstr, .1);
  2. if (! $ open) {
  3. echo '<b> <font color=green> Online </ font> </ b>';
  4. }else {
  5. echo '<b> <font color=red> Offline </ font> </ b>';
  6. }?> <br>


or does php enclose a whole if statement with {} including its else statement inside?
Circa
Clown
Clown
 
Posts: 404
Joined: Sun Aug 23, 2009 5:52 am
Location: CA

Re: Help this php code

Postby kondeddie on Tue Jan 08, 2013 10:23 pm

I could have had to put where 127.0.0.1 localhost to work there ..

Thanks for the trouble.

xD
kondeddie
Jelly Bean
Jelly Bean
 
Posts: 23
Joined: Wed Dec 26, 2012 10:12 pm

Re: Help this php code

Postby observe on Tue Jan 22, 2013 4:42 pm

Try this
  1. <?PHP
  2.     $ip    = '127.0.0.1'; // Ip adress to connect
  3.     $port = '29000';      // Port to check
  4.     $open = @fsockopen($ip,$port,$ERRNO,$ERRSTR, 1);
  5.  
  6.     if($open){
  7.         $status = '<font color="green">Online</font>';
  8.     } else {
  9.         $status = '<font color="red">Offline</font>';
  10.     }
  11. ?>
  12.  
  13. Server Status: <?= $status; ?>
  14.  
observe
osRose dev
osRose dev
 
Posts: 194
Joined: Thu Sep 17, 2009 10:28 am
Location: The Netherlands


Return to PHP / Web Guides, Scripts and tools.

Who is online

Users browsing this forum: No registered users and 9 guests