Php 我在检查服务器状态时遇到一些问题
我正在尝试制作一个脚本,在这个脚本中,我可以检查服务器的状态(在线/离线),例如:Teamspeek、Minecraft和其他服务器 我发现这个脚本:Php 我在检查服务器状态时遇到一些问题,php,mysql,fsockopen,Php,Mysql,Fsockopen,我正在尝试制作一个脚本,在这个脚本中,我可以检查服务器的状态(在线/离线),例如:Teamspeek、Minecraft和其他服务器 我发现这个脚本: <?php function getStatus($ip,$port){ $socket = @fsockopen($ip, $port, $errorNo, $errorStr, 3); if(!$socket) return "offline"; else r
<?php
function getStatus($ip,$port){
$socket = @fsockopen($ip, $port, $errorNo, $errorStr, 3);
if(!$socket) return "offline";
else return "online";
}
echo getStatus("server.com", "80");
?>
但是不必更改服务器名称和端口I 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();
}
}
?>
第一件事。使用mysqli_uu而不是mysql
其次,如果将结果限制为1,则不需要while循环
现在,当您在get方法中获取id时,您可以在数据库中检查它并获取详细信息:
从数据库获取详细信息后,必须启动函数getStatus()
if ($productCount == 1){
echo getStatus($row["ip"],$row["port"]);
} else {
echo "That item does not exist.";
}
$ip
和$port
的值是多少?