我想製作一個腳本,可以幫助服務器狀態(聯機/脫機),例如Teamspeek,Minecraft和其他服務器。我對服務器的狀態感到一些問題
我發現這個腳本:
<?php
function getStatus($ip,$port){
$socket = @fsockopen($ip, $port, $errorNo, $errorStr, 3);
if(!$socket) return "offline";
else return "online";
}
echo getStatus("server.com", "80");
?>
,而不必改變我wnat從MySQL數據庫得到它的服務器名稱和端口但是。 所以我做了這個,但我的問題是:我無法獲取連接到腳本的字符串。 我的代碼來獲取字符串看起來是這樣的:
<?php
// Check to see the URL variable is set and that it exists in the database
if (isset($_GET['id'])) {
// Connect to the MySQL database
include "connect_mysql.php";
$id = preg_replace('#[^0-9]#i', '', $_GET['id']);
// Use this var to check to see if this ID exists, if yes then get the product
// details, if no then exit this script and give message why
$sql = mysql_query("SELECT * FROM servers WHERE id='$id' LIMIT 1");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
// get all the product details
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$ip = $row["ip"];
$port = $row["port"];
$getit = $row["getit"];
$name = $row["name"];
$content = $row["content"];
}
} else {
echo "That item does not exist.";
exit();
}
}
?>
所以我想我只是可以改變echo getStatus("server.com", "80");
要echo getStatus("$ip", "$port");
但是,這並不工作。 有沒有人知道我必須做什麼?
'$ ip'和'$ port'的值是什麼? –