Page 1 of 1

Minequery tutorial help

Posted: Thu Aug 18, 2011 5:09 pm
by robinatorzzz
Hye so i get a bunch of errors, first of all, here is my code:

Index.php
<?php 	
include ('core/init.inc.php');

$info = fetch_server_info($config['server']['ip'], $config['server']['port']);

?>
<html>
<head>
	<title><?php echo $config['server']['ip']; ?> Status</title>
</head>
<body>
	<div>
		<h1><?php echo $config['server']['ip']; ?></h1>
		
		<?php 
		if ($info === false){
			?>
			<p>
				Status: Offline
			</p>
			<?php 
		}else{
			?>
			<p>
				Status: Online
			</p>
			<p>
				Slots: <?php echo $info['playerCount'];?> / <?php echo $info['maxPlayers'];?>
			</p>
			<p>
				Players: <?php echo implode('', $info['playerList']);?>
			</p>
			<?php 
		}
		?>
	</div>
</body>
</html>
core/config.inc.php
<?php
$config['server']['ip']   = 'robinatorzzzz.zapto.org';
$config['server']['port'] = '25565';
?>
core/init.inc.php
<?php
$path = dirname(__FILE__);

include ("{$path}/config.inc.php");
include ("{$path}/inc/mc.inc.php");
?>
core/inc/mc.inc.php
<?php

// fetches server information from minequery.
function fetch_server_info($ip, $port){
	$socket = fsockopen($ip, $port, $errno, $errstr, 0.5);
	
	if($socket === false){
		return false;
	}
	
	fwrite($socket, "QUERY_JSON\n");
	
	$response = stream_get_contents($socket);
	
	return json_decode($response, true);
}
?>
The errors i get...

Erro NR 1 (When the server is offline)

Warning: fsockopen() [function.fsockopen]: unable to connect to robinatorzzzz.zapto.org:25565 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\xampp\htdocs\workspace\minecraft server - minequery\core\inc\mc.inc.php on line 5

Output:
robinatorzzzz.zapto.org

Status: Offline


Erro NR 2 (When the server is online)

Warning: implode() [function.implode]: Invalid arguments passed in C:\xampp\htdocs\workspace\minecraft server - minequery\index.php on line 31

Output:
robinatorzzzz.zapto.org

Status: Online

Slots: /

Players:





Thnx in advance!!

Re: Minequery tutorial help

Posted: Thu Aug 18, 2011 7:25 pm
by jacek
Ah okay, I should have mentioned this in the video, when the server is offline the connection does fail so this error is normal. It's explain a bit more in the other minecraft video on the server status page. The fix is to put a @ before the fsockopen line.
robinatorzzz wrote:Warning: implode() [function.implode]: Invalid arguments passed in C:\xampp\htdocs\workspace\minecraft server - minequery\index.php on line 31
Can you add a print_r($info) before the implode line ? I have never seen this erorr before, it would normally say why they are invalid. Are you sure you are using a recent version of php ?

Re: Minequery tutorial help

Posted: Thu Aug 18, 2011 7:47 pm
by robinatorzzz
Print_r doesn't do anything, this is my php version


PHP Version 5.3.5

Re: Minequery tutorial help

Posted: Sat Aug 20, 2011 12:09 pm
by jacek
robinatorzzz wrote:Print_r doesn't do anything, this is my php version
it should have done, can you post the code you are using with the print_r ?

also make sure you have error_reporting set to E_ALL as that will show up any variable name typos that would otherwise be hard to spot.

Re: Minequery tutorial help

Posted: Sat Sep 24, 2011 7:15 pm
by Pel02
Hello, I really liked your video tutorials!
I have a similar problem, but I have no any error. Connection to the server is successful, but info array is empty.
error_reporting was set to E_ALL

Re: Minequery tutorial help

Posted: Mon Sep 26, 2011 4:52 pm
by jacek
Try outputting the response form the server directly, the format may have changed.

Re: Minequery tutorial help

Posted: Mon Sep 26, 2011 7:38 pm
by Pel02
Sorry. How?:)

Re: Minequery tutorial help

Posted: Tue Sep 27, 2011 3:11 pm
by jacek
Pel02 wrote:Sorry. How?:)
Add an echo...
echo $responce;
:D

Re: Minequery tutorial help

Posted: Tue Sep 27, 2011 6:02 pm
by Pel02
This does not work. '$responce' is empty. :(

Re: Minequery tutorial help

Posted: Tue Sep 27, 2011 7:47 pm
by robinatorzzz
maybe it is $response instead of $responce...

Re: Minequery tutorial help

Posted: Wed Sep 28, 2011 1:07 pm
by jacek
Pel02 wrote:This does not work. '$responce' is empty. :(
robinatorzzz wrote:maybe it is $response instead of $responce...
^^ Make sure you have the variable name right. If it is right, try var_dump($responce);

Re: Minequery tutorial help

Posted: Wed Sep 28, 2011 8:08 pm
by Pel02
var_dump($responce) = NULL ;(

Re: Minequery tutorial help

Posted: Fri Sep 30, 2011 5:51 pm
by jacek
Pel02 wrote:var_dump($responce) = NULL ;(
I think we are alternating between response and responce, you should var_dump() that variable that you assigned the result of the stream_get_contents() function to.

Re: Minequery tutorial help

Posted: Thu May 17, 2012 6:49 am
by Helx
Change the port in config.inc.php from 25565 to 25566, this is the default MineQuery port :)
$config['server']['port'] = '25566';