PHP and my webhost and XAMPP?
#1

Hi guys. I have a very simple script which i will hopefully be making dynamic so that the page does not need to be refreshed, that displays some simple server stats. My goal is to make this dynamic so that when the server updates, it updates. But that's not the point. I am here to ask you about why it works correctly on XAMPP and not my web host. My web host does support PHP... so.. heres the code:

Код:
<html>
<?php
getstats();

function getstats()
{
  $ip = "24.111.46.103";
  $port = "7777";
  $fp = fsockopen('udp://' . $ip, $port, $errno, $errstr,0.0);
  if (!$fp)
  {
     echo " offline";
  }
  else
  {
    $packet = 'SAMP';
    $packet .= chr(strtok($ip, '.'));
    $packet .= chr(strtok('.'));
    $packet .= chr(strtok('.'));
    $packet .= chr(strtok('.'));
    $packet .= chr($port & 0xFF);
    $packet .= chr($port >> 8 & 0xFF);

    fwrite($fp, $packet.'i');
    fread($fp, 11);

    $is_passworded = ord(fread($fp, 1));
    $plr_count     = ord(fread($fp, 2));
    $max_plrs      = ord(fread($fp, 2));
    $strlen        = ord(fread($fp, 4));
    $hostname      = htmlentities(fread($fp, $strlen));
    $strlen        = ord(fread($fp, 4));
    $gamemode      = htmlentities(fread($fp, $strlen));
    $strlen        = ord(fread($fp, 4));
    $mapname       = htmlentities(fread($fp, $strlen));
	
	if($is_passworded == 1)
	{
		$is_passworded = "yes";
	}
	else if($is_passworded == 0)
	{
		$is_passworded = "no";
	}	
	
    echo "Hostname  : $hostname " . "<br>";
    echo "Gamemode : $gamemode ". "<br>";
    echo "Map : $mapname ". "<br>";
    echo "Players: $plr_count/$max_plrs". "<br>";
    echo "Passoword: $is_passworded". "<br>";
	
    fwrite($fp, $packet.'c');
    fread($fp, 11);
    fclose($fp);
 }	
}
?>
</html>
And again, it works on XAMPP but not lockernerd.co.uk. And just so you know, the ip in that code is the port-forwarded one. Also, (again) you can save this code in a php file and change the ip/port for your server and try it out if you want. I will be making a tutorial however once I get everything working 100% and make it look decent. Anyway, my question is, how can i make this work on the web? It just says offline while when i connect to the XAMPP one, it shows the server's stats. So.. what to do? Thank you for reading and thanks in advance for commenting. Have a nice day/night.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)