I have a script that should whitelist people on my minecraft server remotely from my webserver.
This script works perfectly when ran from my localhost, but not when ran on my web server (Connection timeout). Is there anything that would make this happen?
<?php
require('../private/config.php');
function connectDB($user, $pass, $db) {
try {
return(new PDO("mysql:host=localhost;dbname=" . $db . ";charset=utf8", $user, $pass));
} catch(PDOException $ex) {
return $ex;
}
}
$db = connectDB($dbUser, $dbPass, $dbName);
if ($db instanceof PDOException) {
die ($db->getMessage());
}
if(!isset($_GET['user']) || $_GET['user']=='') {
die('User undefined.');
}
if(!isset($_GET['pw']) || $_GET['pw']=='') {
die('Not Authorised.');
}
if($_GET['pw']!=$whitelistpassword) {
die('Not Authorised.');
}
$user = $_GET['user'];
define( 'MQ_SERVER_ADDR', '[ip]' );
define( 'MQ_SERVER_PORT', 25605 );
define( 'MQ_SERVER_PASS', 'passwordtest' );
define( 'MQ_TIMEOUT', 5 );
require 'MinecraftQuery/MinecraftRcon.class.php';
try
{
$Rcon = new MinecraftRcon;
$Rcon->Connect( MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_SERVER_PASS, MQ_TIMEOUT );
$Data = $Rcon->Command("whitelist add ".$user);
if($Data===false) {
throw new MinecraftRconException("Failed to get command result.");
}
else if(StrLen($Data)==0) {
throw new MinecraftRconException("Got command result, but it's empty.");
}
//echo HTMLSpecialChars($Data);
}
catch( MinecraftRconException $e )
{
header('Location: approve.php?pw='.$whitelistpassword);
die('Error');
}
$Rcon->Disconnect();
$sql = "UPDATE `Applications` SET `Approved` = 1 WHERE `Minecraft` = :user";
$stmt = $db->prepare($sql);
$stmt->bindParam(':user', $user);
$stmt->execute();
header('Location: approve.php?pw='.$whitelistpassword);
?>
Every time I run it from the webserver, it times out. Then the minecraft server crashes.
Expected: "User" has been added to whitelist (works from localhost) Actual from web server:
Warning: fsockopen() [function.fsockopen]: unable to connect to [ip]:25605 (Connection timed out) in /home/dooog/public_html/MinecraftQuery/MinecraftRcon.class.php on line 38
Warning: Cannot modify header information - headers already sent by (output started at /home/dooog/public_html/MinecraftQuery/MinecraftRcon.class.php:38) in /home/dooog/public_html/whitelistsend.php on line 57