Bonjour à toutes et tous,
voici un tuto de Mogui:
voici un tuto de Mogui:
Mogui a écrit:Voici un petit Guide expliquant la méthode pour afficher le Status de son Serveur.
La Méthode
Il s'agit en fait d'une Image en PHP. Un script va envoyé un Ping au Serveur et en cas de réponse il affichera ONLINE, sinon il affichera OFFLINE.
1. Créer un ficher "test.php"
2. Copiez le Code suivant:
[php] header ("Content-type: image/png");
$status = GetServerStatus('##IP_PING##',##PORT_PING##);
$server_name = "##NOM###";
$ip_txt = "##IP##";
$port_txt = "##PORT##";
$im = ImageCreate (300, 90)
or die ("Erreur lors de la création de l'image");
$couleur_fond = ImageColorAllocate ($im, 220, 220, 255);
$couleur_border = ImageColorAllocate ($im, 0, 0, 0);
if ($status == "ONLINE") {
$couleur_server = ImageColorAllocate ($im, 0, 255, 0);
} else {
$couleur_server = ImageColorAllocate ($im, 255, 0, 0);
}
$couleur_txt = ImageColorAllocate ($im, 0, 0, 0);
$couleur_infos = ImageColorAllocate ($im, 50, 50, 50);
ImageRectangle($im, 0, 0, 299, 89, $couleur_border);
ImageString($im, 5, 10, 5, $server_name, $couleur_txt);
ImageString($im, 4, 10, 30, "Etat:", $couleur_txt);
ImageString($im, 5, 65, 30, $status, $couleur_server);
ImageString($im, 4, 10, 50, "IP:", $couleur_txt);
ImageString($im, 4, 65, 50, $ip_txt, $couleur_infos);
ImageString($im, 4, 10, 70, "Port:", $couleur_txt);
ImageString($im, 4, 65, 70, $port_txt, $couleur_infos);
ImagePng ($im);
function GetServerStatus($site, $port) {
$status = array("OFFLINE", "ONLINE");
$fp = @fsockopen($site, $port, $errno, $errstr, 2);
if (!$fp) {
return $status[0];
} else {
return $status[1];}
}
?>
[/php]
3. Editez ces 4 lignes:
[php] $status = GetServerStatus('##IP_PING##',##PORT_PING##);
$server_name = "##NOM###";
$ip_txt = "##IP##";
$port_txt = "##PORT##";[/php]
##IP_PING## = l'IP de votre Serveur pour le Ping
##PORT_PING## = Le Port d'accès au Serveur pour le Ping
##NOM## = Le Nom qui sera affiché
##IP## = L'IP qui sera affichée.
##PORT## = Le Port qui sera affiché.
4. Envoyez votre ficher "test.php" sur un FTP.
5. Vous l'afficherez comme une image normal, par exemple sur ce forum il suffit de mettre l'URL de "test.php" entre les balises ]'IMG]##URL/test.php]'/IMG]