PHP Tutorial: Minecraft Server Information (No Plugins Neede
PHP Tutorial: Minecraft Server Information (No Plugins Neede
I am getting a fsocket error that says that the connection timed out, but the server is clearly on im in it right now. Please help
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
Post the code that you have. We won't be able to help you without it.
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
Actualy I just figured out that its not my code but my host, I either need to move to a new host or upgrade mine because right now the port is locked on there side and wont unlock it unless I uprgade
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
Most VPS services have all ports open.
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
Ok well im actualy using 00webhost since it was free and im using it for testing reasons, and when i sent them a ticket asking about the port they told me they have it closed. Now im not sure if there just saying that to get me to buy, so here is my code.
this is the mc.inc.php
[syntax=php]<?php
function fetch_server_info($ip, $port){
$socket = fsockopen($ip, $port, $errno, $errstr, 0.5);
if($socket === false){
return false;
}
fwrite($socket, "\xfe");
$data = fread($socket, 256);
if(substr($data, 0, 1) != "\xff"){
return false;
}
$data = explode('§', mb_convert_encoding(substr($data, 3), 'UTF8', 'UCS-2'));
return array(
'motd' => $data[0],
'players' => intval($data[1]),
'max_players' => intval($data[2]),
);
}
?>[/syntax]
this is the index page code
[syntax=php]<?PHP
include('PHP/core/init.inc.php');
foreach ($config['servers'] as $server){
$server_ip = $server[0];
$server_port = $server[1];
}
$info = fetch_server_info($server_ip, $server_port);
?>
<div id="box4">
<?PHP
echo '<h3>', $server_ip, '</h3>';
if($info === false){
echo '<p><font color = "#FFF000">Status:</font> <font color = "#FF0000">Offline</font></P>';
echo '<font color = "#FFF000">Note: If this says ofline but your positive the server is online
check your fire wall or internet connection</font>';
}else{
echo '<p><font color = "#FFF000">Status:</font> <font color = "#00FF00">Online</font></p>';
echo '<p><font color = "#FFF000">Motd: ', $info['motd'], '</font></p>';
echo '<p><font color = "#FFF000">Players:', $info['players'], ' / ', $info['max_players'], '</font></p>';
}
?>
</div>
[/syntax]
this is the mc.inc.php
[syntax=php]<?php
function fetch_server_info($ip, $port){
$socket = fsockopen($ip, $port, $errno, $errstr, 0.5);
if($socket === false){
return false;
}
fwrite($socket, "\xfe");
$data = fread($socket, 256);
if(substr($data, 0, 1) != "\xff"){
return false;
}
$data = explode('§', mb_convert_encoding(substr($data, 3), 'UTF8', 'UCS-2'));
return array(
'motd' => $data[0],
'players' => intval($data[1]),
'max_players' => intval($data[2]),
);
}
?>[/syntax]
this is the index page code
[syntax=php]<?PHP
include('PHP/core/init.inc.php');
foreach ($config['servers'] as $server){
$server_ip = $server[0];
$server_port = $server[1];
}
$info = fetch_server_info($server_ip, $server_port);
?>
<div id="box4">
<?PHP
echo '<h3>', $server_ip, '</h3>';
if($info === false){
echo '<p><font color = "#FFF000">Status:</font> <font color = "#FF0000">Offline</font></P>';
echo '<font color = "#FFF000">Note: If this says ofline but your positive the server is online
check your fire wall or internet connection</font>';
}else{
echo '<p><font color = "#FFF000">Status:</font> <font color = "#00FF00">Online</font></p>';
echo '<p><font color = "#FFF000">Motd: ', $info['motd'], '</font></p>';
echo '<p><font color = "#FFF000">Players:', $info['players'], ' / ', $info['max_players'], '</font></p>';
}
?>
</div>
[/syntax]
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
also what vps hos would you suggest.
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
I would suggest x10vps.com (link).
If you have any problems with their service, you can always submit a ticket.
There customer service is excellent
If you have any problems with their service, you can always submit a ticket.
There customer service is excellent
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
Ok ill give it a try thanks for the help.
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
ok so i got the server and the php code sorta works, it connects to it, but the motd doesnt show, it shows A with a squigly line above it , and then the players go either 0/0 or 4/0
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
ok so i figured out something, its actualy a color code this is what i am getting array(7) { [0]=> string(1) "Â" [1]=> string(6) "4MineÂ" [2]=> string(6) "bMad Â" [3]=> string(14) "4Multi-World Â" [4]=> string(9) "f[1.5.1]Â" [5]=> string(2) "1Â" [6]=> string(2) "15" } how can i clean it up in my code so it looks like MineMad Multi-World [1.5.1] then for the players to be 1/15 with out the  after the 1
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
In your <head> try putting this: <meta charset="utf-8">
See if that helps
See if that helps
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
Helx wrote:In your <head> try putting this: <meta charset="utf-8">
See if that helps
That didnt, work if you look at the code above im already doing that in the php code.
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
any other idea please,
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
Line 18 of mc.inc.php, change UTF8 to utf-8
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
Helx wrote:Line 18 of mc.inc.php, change UTF8 to utf-8
Nope didn't work, that shouldn't have mattered at all since UTF8 and utf-8 are the same thing, in minecraft my friend has color codes around his motd which look like this §a, well since im already exploding the §, im thinking the php is still trying to say ok what in UTF8 will match the color codes that minecraft is sending and is replacing them with  and what ever number is ment to be with it for the color.
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
if there are any more ideas i would loe to here them, cause this is pissing me off.
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
I really have no clue :/
All I can suggest is that you put
[syntax=php]error_reporting(E_ALL);
ini_set('display_errors', '1');[/syntax]
At the top of your code and see if anything comes up.
All I can suggest is that you put
[syntax=php]error_reporting(E_ALL);
ini_set('display_errors', '1');[/syntax]
At the top of your code and see if anything comes up.
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
its not error though, im not getting an error, I found help some were else thanks for trying though.
- FrederickGeek8
- Posts: 148
- Joined: Wed Nov 30, 2011 10:31 pm
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
I don't know where the error is coming from but you could just preg_replace everything in the arrays.
[syntax=php]$example = array( [0]=> "Â" [1]=> "4MineÂ" [2]=> "bMad Â" [3]=> "4Multi-World Â" [4]=> "f[1.5.1]Â" [5]=> "1Â" [6]=> "15" );
$pattern = array('\Â\', '\4\');
implode(' ', preg_replace($pattern, '', array_slice($example, 0, -2)));
[/syntax]
That would *probably* take care of the title. You can apply the same method to the player count just changed the offset of array_slice.
[syntax=php]$example = array( [0]=> "Â" [1]=> "4MineÂ" [2]=> "bMad Â" [3]=> "4Multi-World Â" [4]=> "f[1.5.1]Â" [5]=> "1Â" [6]=> "15" );
$pattern = array('\Â\', '\4\');
implode(' ', preg_replace($pattern, '', array_slice($example, 0, -2)));
[/syntax]
That would *probably* take care of the title. You can apply the same method to the player count just changed the offset of array_slice.
Re: PHP Tutorial: Minecraft Server Information (No Plugins N
Hello,
I'm still having some issues with utf8 stuff.
I'm still getting the triangles.
here's my mc.inc.php code:
[syntax=php]<?php
function fetch_server_info($ip, $port){
$socket = @fsockopen($ip, $port, $errno, $errstr, 0.5);
if($socket === false){
return false;
}
fwrite($socket, "\xFE");
$data = fread($socket, 256);
//var_dump($data);
if(substr($data, 0, 1) != "\xFF"){
return false;
}
$data = explode('§', mb_convert_encoding(substr($data, 3), 'UTF8', 'UCS-2'));
var_dump($data);
return array(
'motd' => $data[0],
'players' => intval($data[1]),
'max_players' => intval($data[2]),
);
}
?>[/syntax]
server_list.php
[syntax=php]<?php
include('core/init.inc.php');
?>
<!DOCTYPE html public "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Minecraft server list</title>
</head>
<body>
<div>
<?php
foreach($config['servers'] as $id => $server){
echo '<p><a href="view_server.php?sid=', $id, '">', $server[0],'</a></p>';
}
?>
</div>
</body>
</html>[/syntax]
view_server.php
[syntax=php]<?php
include('core/init.inc.php');
if (!isset($_GET['sid']) || empty($config['servers'][$_GET['sid']])){
header('location: server_list.php');
die();
}
$server_ip = $config['servers'][$_GET['sid']][0];
$server_port = $config['servers'][$_GET['sid']][1];
$info = fetch_server_info($server_ip, $server_port);
?>
<!DOCTYPE html public "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $server_ip; ?> Status</title>
</head>
<body>
<div>
<h1><?php echo $server_ip; ?></h1>
<?php
if($info === false){
echo '<p>Status: <span style="color:red">Offline</span></p>';
}else{
echo '<p>Status: <span style="color:green">Online</span></p>';
echo '<p>Motd: ', $info['motd'], '</p>';
echo '<p>Players: ', $info['players'],' / ',$info['max_players'], '</p>';
}
?>
</div>
<a href="server_list.php">Back</a>
</body>
</html>[/syntax]
config.inc.php
[syntax=php]<?php
$config['servers'][] = array('bearlyconnected.com', 25565);
$config['servers'][] = array('bearlyconnected.com', 25566);
$config['servers'][] = array('bearlyconnected.com', 25567);
$config['servers'][] = array('server.mcbans.com', 25565);
?>[/syntax]
Please help with this issue if possible.
I'm still having some issues with utf8 stuff.
array(3) { [0]=> string(20) "Minecraft Adventure�" [1]=> string(2) "0�" [2]=> string(2) "20" }
I'm still getting the triangles.
here's my mc.inc.php code:
[syntax=php]<?php
function fetch_server_info($ip, $port){
$socket = @fsockopen($ip, $port, $errno, $errstr, 0.5);
if($socket === false){
return false;
}
fwrite($socket, "\xFE");
$data = fread($socket, 256);
//var_dump($data);
if(substr($data, 0, 1) != "\xFF"){
return false;
}
$data = explode('§', mb_convert_encoding(substr($data, 3), 'UTF8', 'UCS-2'));
var_dump($data);
return array(
'motd' => $data[0],
'players' => intval($data[1]),
'max_players' => intval($data[2]),
);
}
?>[/syntax]
server_list.php
[syntax=php]<?php
include('core/init.inc.php');
?>
<!DOCTYPE html public "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Minecraft server list</title>
</head>
<body>
<div>
<?php
foreach($config['servers'] as $id => $server){
echo '<p><a href="view_server.php?sid=', $id, '">', $server[0],'</a></p>';
}
?>
</div>
</body>
</html>[/syntax]
view_server.php
[syntax=php]<?php
include('core/init.inc.php');
if (!isset($_GET['sid']) || empty($config['servers'][$_GET['sid']])){
header('location: server_list.php');
die();
}
$server_ip = $config['servers'][$_GET['sid']][0];
$server_port = $config['servers'][$_GET['sid']][1];
$info = fetch_server_info($server_ip, $server_port);
?>
<!DOCTYPE html public "-//W3C//DTD XHTML 1.1 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?php echo $server_ip; ?> Status</title>
</head>
<body>
<div>
<h1><?php echo $server_ip; ?></h1>
<?php
if($info === false){
echo '<p>Status: <span style="color:red">Offline</span></p>';
}else{
echo '<p>Status: <span style="color:green">Online</span></p>';
echo '<p>Motd: ', $info['motd'], '</p>';
echo '<p>Players: ', $info['players'],' / ',$info['max_players'], '</p>';
}
?>
</div>
<a href="server_list.php">Back</a>
</body>
</html>[/syntax]
config.inc.php
[syntax=php]<?php
$config['servers'][] = array('bearlyconnected.com', 25565);
$config['servers'][] = array('bearlyconnected.com', 25566);
$config['servers'][] = array('bearlyconnected.com', 25567);
$config['servers'][] = array('server.mcbans.com', 25565);
?>[/syntax]
Please help with this issue if possible.