ID:186951
 
Code:
<?php
$gamelive=true;
$SERVER_ADDRESS="127.0.0.1";
$SERVER_PORT=5000
$TIMEOUT=3 // Line 5
if($gamelive==true){
$check = pfsockopen ($SERVER_ADDRESS, $SERVER_PORT, &$errno, &$errstr, 5);
if (!$check) {
echo "<font color=\"#FF0000\>offline </font>";

} else {
echo "<font color=\"#00FF00\">online</font>";
fclose($fp);
};
};?>


Problem description:
Parse error: parse error, unexpected T_VARIABLE in /home2/glowner/public_html/JiskGames/coh/server.php on line 5

its basically a PHP script that shows a live game however it gives me that error for that line. Any help?

~>Jiskuha
Jiskuha wrote:
> <?php
> $gamelive=TRUE;
> $SERVER_ADDRESS="127.0.0.1";
> $SERVER_PORT=5000;
> $TIMEOUT=3; // Line 5
> if($gamelive){
> $check = pfsockopen ($SERVER_ADDRESS, $SERVER_PORT, &$errno, &$errstr, 5);
> if (!$check) {
> echo "<font color=\"#FF0000\>offline </font>";
>
> } else {
> echo "<font color=\"#00FF00\">online</font>";
> fclose($fp);
> }
> }?>
>


I've fixed the error, you didn't have semi-colons after the SERVER_PORT and TIMEOUT variables.
In response to Nadrew
Thanks nadz. You are the man =P.

One last problem.

When its offline:


Warning: pfsockopen(): unable to connect to 127.0.0.1 in /home2/glowner/public_html/JiskGames/coh/server.php on line 7


When its online:

Warning: fclose(): supplied argument is not a valid stream resource in /home2/glowner/public_html/JiskGames/coh/server.php on line 13


How would i go about fixing the this?

(Please keep in mind i don't know any php.)

~>Jiskuha
In response to Jiskuha
Try this.

<?php
$gamelive=TRUE;
$SERVER_ADDRESS="127.0.0.1";
$SERVER_PORT=5000;
$TIMEOUT=3; // Line 5
if($gamelive){
$check = @fsockopen($SERVER_ADDRESS, $SERVER_PORT, &$errno, &$errstr, 5);
if ($check === FALSE) {
echo "<font color=\"#FF0000\>offline </font>";

} else {
echo "<font color=\"#00FF00\">online</font>";
}
}?>


I changed pfsockopen to fsockopen; you don't want a persistent connection. I also used the @ operator to suppress the warning you were getting from the (p)fsockopen function, and changed the $check comparison to be more explicit (probably not necessary, but just in case). Hopefully that works a bit better.
In response to Crispy
Thanks. One last question, how could i pull the amount of players(in a number) off the hub page and have it be ported to a web page?

~>Jiskuha
In response to Jiskuha
Mmmm... that's more difficult. Getting it off the hub page requires downloading the page and parsing it to find the player list, and it relies on the hub's player list (which is sometimes inaccurate).

If I were you, I'd keep a count separate from the hub's count and use that instead. As you're hosting on the same machine as the PHP file is located on, you could make the game save a text file somewhere with a player count, and then have the PHP script read the text file.

A cleaner solution might be to make the PHP script send a "ping" message (see world/Export() and world/Topic() in the reference), but then you'd have to reverse engineer the protocol BYOND uses for that, and that's (A) difficult and (B) in a legal grey area. Using DMCGI would let you use world/Export() to make BYOND handle it, but you probably don't have access to DMCGI.