How can PHP scripts be used to display the online/offline status of a locally hosted TeamSpeak server on a website?

To display the online/offline status of a locally hosted TeamSpeak server on a website using PHP, you can create a PHP script that checks the server's status by attempting to connect to it using a socket connection. If the connection is successful, the server is online; otherwise, it is offline. You can then display this status on your website by calling this PHP script.

<?php
$serverAddress = '127.0.0.1';
$serverPort = 10011;

$socket = @fsockopen($serverAddress, $serverPort, $errno, $errstr, 1);

if ($socket) {
    echo 'Server is online';
    fclose($socket);
} else {
    echo 'Server is offline';
}
?>