J'essaye de faire un script où je peux examiner l'état du serveur (en ligne/hors ligne) pour des serveurs comme: Teamspeek, Minecraft et d'autres.J'ai quelques problèmes avec le statut d'un serveur
Je trouve ce script:
<?php
function getStatus($ip,$port){
$socket = @fsockopen($ip, $port, $errorNo, $errorStr, 3);
if(!$socket) return "offline";
else return "online";
}
echo getStatus("server.com", "80");
?>
Mais au lieu d'avoir à changer le nom et le port sever je wnat pour l'obtenir à partir d'une base de données MySQL. J'ai donc fait cela, mais mon problème est le suivant: je n'arrive pas à connecter la chaîne au script. Mon code pour obtenir la chaîne ressemble à ceci:
<?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();
}
}
?>
Je pensais que je ne pouvais changer le echo getStatus("server.com", "80");
Pour echo getStatus("$ip", "$port");
Mais cela ne fonctionne pas. Y a-t-il quelqu'un qui sait ce que je dois faire?
Quelle est la valeur de $ IP et $ port? –