DerekDev
DerekDev

Reputation: 63

Server Online Player Count Ping PHP

so I got this code together to ping the Online Player Count/Max Player Slots for my server. I think I've got everything done correctly, but this error occurs...any suggestions on how to fix it? Here is the error: Parse error: syntax error, unexpected '<' in /home/u7335206/public_html/mc-vr.com/pc.php on line 21

Here is my code:

<?php
require "MinecraftQuery.class.php";

// Variables for each of your servers: 
$server_info = array();

try 
{
// Getting Server Info:
$query = new MinecraftQuery();
$query->Connect("192.99.14.177", 25573);
$server_info = $query->GetInfo();
} 
catch(MinecraftQueryException $e) 
{
// Getting the information failed.
}

try 
{
<?php if ($server_info) { ?>
<p><span style='font-family: Arial; font-weight: normal; font-style: normal; text-decoration: none;'><font       color='#FFFFFF'><?= $server_info["numplayers"] ?>/<?= $server_info["maxplayers"] ?></font></span></p>
<?php } else { ?>
<p><span style='font-family: Arial; font-weight: normal; font-style: normal; text-decoration: none;'><font   color='#FFFFFF'>0/120</span></font></p>
<?php } ?>

Upvotes: 0

Views: 333

Answers (1)

Sean
Sean

Reputation: 12433

Change

try 
{
<?php if ($server_info) { ?>

to

try 
{
if ($server_info) { ?>

You are also missing your closing bracket for the try. But since you are not doing a catch(), just remove the try

<?php
require "MinecraftQuery.class.php";

// Variables for each of your servers: 
$server_info = array();

try 
{
// Getting Server Info:
$query = new MinecraftQuery();
$query->Connect("192.99.14.177", 25573);
$server_info = $query->GetInfo();
} 
catch(MinecraftQueryException $e) 
{
// Getting the information failed.
}

if ($server_info) { ?>
<p><span style='font-family: Arial; font-weight: normal; font-style: normal; text-decoration: none;'><font       color='#FFFFFF'><?= $server_info["numplayers"] ?>/<?= $server_info["maxplayers"] ?></font></span></p>
<?php } else { ?>
<p><span style='font-family: Arial; font-weight: normal; font-style: normal; text-decoration: none;'><font   color='#FFFFFF'>0/120</span></font></p>
<?php } ?>

Upvotes: 1

Related Questions