• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

OTClient status.php (Player Online)

Piifafa

Member
Joined
Apr 16, 2023
Messages
66
Reaction score
16
Hey friends, I managed to fix my discord, but the player number hasn't worked even though I put the website there, how should I fix this problem?

status.php page:
PHP:
<?php
$online_otservlist = 0;
try {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://otservlist.org/");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return data inplace of echoing on screen
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Skip SSL Verification
    curl_setopt($ch, CURLOPT_ENCODING , "");
    $site = curl_exec($ch);
    curl_close($ch);
    
    preg_match('/There are <strong>([0-9]*)<\/strong>/', $site, $matches);
    $online_otservlist = $matches[1];
} catch(Exception $e) {}
$online_discord = 0;
try {
    $online_discord = json_decode(file_get_contents("https://discordapp.com/api/guilds/628769144925585428/widget.json"))->presence_count;
} catch(Exception $e) {}

$response = array(
    "online" => "$online_otservlist Players online",
    "discord_online" => $online_discord,
    "discord_link" => "https://discord.gg/t4ntS5p"
);
echo json_encode($response);
?>

I remember that there used to be a news.php page, I would like to activate this again, how should I do it?
PHP:
-- If you don't use updater or other service, set it to updater = ""
Services = {
  website = "http://************", -- currently not used
  updater = "http://************/api/updater.php",
  news = "http://************/api/news.php",
  stats = "",
  crash = "http://************/api/crash.php",
  feedback = "http://************/api/feedback.php"
}
 
Hey friends, I managed to fix my discord, but the player number hasn't worked even though I put the website there, how should I fix this problem?

status.php page:
PHP:
<?php
$online_otservlist = 0;
try {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://otservlist.org/");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return data inplace of echoing on screen
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Skip SSL Verification
    curl_setopt($ch, CURLOPT_ENCODING , "");
    $site = curl_exec($ch);
    curl_close($ch);
  
    preg_match('/There are <strong>([0-9]*)<\/strong>/', $site, $matches);
    $online_otservlist = $matches[1];
} catch(Exception $e) {}
$online_discord = 0;
try {
    $online_discord = json_decode(file_get_contents("https://discordapp.com/api/guilds/628769144925585428/widget.json"))->presence_count;
} catch(Exception $e) {}

$response = array(
    "online" => "$online_otservlist Players online",
    "discord_online" => $online_discord,
    "discord_link" => "https://discord.gg/t4ntS5p"
);
echo json_encode($response);
?>

I remember that there used to be a news.php page, I would like to activate this again, how should I do it?
PHP:
-- If you don't use updater or other service, set it to updater = ""
Services = {
  website = "http://************", -- currently not used
  updater = "http://************/api/updater.php",
  news = "http://************/api/news.php",
  stats = "",
  crash = "http://************/api/crash.php",
  feedback = "http://************/api/feedback.php"
}
Hello my brother!

Try this, it's work fine for me!

PHP:
<?php
$online_otservlist = 0;
try {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://otarchive.com/server/6452daeb8fe898282d5263a7");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return data inplace of echoing on screen
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // Skip SSL Verification
    curl_setopt($ch, CURLOPT_ENCODING , "");
    $site = curl_exec($ch);
    curl_close($ch);
    preg_match('/Informed Players (\d+) \(\d+\)/', $site, $matches);
    // preg_match('/There are: <strong>([0-9]*)<\/strong>/', $site, $matches);
    $doc = new DOMDocument();
    @$doc->loadHTML($site);

    $xpath = new DOMXPath($doc);

    // Find the <th> element with the text "Informed Players"
    $thElement = $xpath->query('//th[contains(text(), "Informed Players")]')->item(0);
    if ($thElement) {
        // Find the element <td> sibling of <th> that contains the number of online players
        $tdElement = $thElement->nextSibling;
        if ($tdElement && $tdElement->nodeName === 'td') {
            $playersOnlineText = $tdElement->nodeValue;
            // Use a regular expression to extract just the number
            if (preg_match('/(\d+)/', $playersOnlineText, $matches)) {
                $playersOnline = $matches[1];
                echo "Players Online: " . $playersOnline;
            }
        }
    }
    $online_otservlist = $matches[1];
} catch(Exception $e) {}
$online_discord = 0;
try {
    $online_discord = json_decode(file_get_contents("https://discord.com/api/guilds/1136264192232525964/widget.json "))->presence_count;
} catch(Exception $e) {}

$response = array(
    "online" => "$online_otservlist Players online",
    "discord_online" => $online_discord,
    "discord_link" => "https://discord.gg/t4ntS5p"
);
echo json_encode($response);
?>
 
or just create an API on your website, which counts the rows in your players_online table (remember to cache it). This way you don't ever have to worry if otservlist or whoever you are polling changes their HTML code...
 
Rodrigo answer works, just remove one line, as it adds text in front of the json.

Remove:
PHP:
echo "Players Online: " . $playersOnline;

It should look like this:
PHP:
<?php
$online_otservlist = 0;
try {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://otarchive.com/server/6452daeb8fe898282d5263a7");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return data inplace of echoing on screen
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // Skip SSL Verification
    curl_setopt($ch, CURLOPT_ENCODING , "");
    $site = curl_exec($ch);
    curl_close($ch);
    preg_match('/Informed Players (\d+) \(\d+\)/', $site, $matches);
    // preg_match('/There are: <strong>([0-9]*)<\/strong>/', $site, $matches);
    $doc = new DOMDocument();
    @$doc->loadHTML($site);

    $xpath = new DOMXPath($doc);

    // Find the <th> element with the text "Informed Players"
    $thElement = $xpath->query('//th[contains(text(), "Informed Players")]')->item(0);
    if ($thElement) {
        // Find the element <td> sibling of <th> that contains the number of online players
        $tdElement = $thElement->nextSibling;
        if ($tdElement && $tdElement->nodeName === 'td') {
            $playersOnlineText = $tdElement->nodeValue;
            // Use a regular expression to extract just the number
            if (preg_match('/(\d+)/', $playersOnlineText, $matches)) {
                $playersOnline = $matches[1];
            }
        }
    }
    $online_otservlist = $matches[1];
} catch(Exception $e) {}
$online_discord = 0;
try {
    $online_discord = json_decode(file_get_contents("https://discord.com/api/guilds/1136264192232525964/widget.json "))->presence_count;
} catch(Exception $e) {}

$response = array(
    "online" => "$online_otservlist Players online",
    "discord_online" => $online_discord,
    "discord_link" => "https://discord.gg/t4ntS5p"
);
echo json_encode($response);
?>
 
Rodrigo answer works, just remove one line, as it adds text in front of the json.

Remove:
PHP:
echo "Players Online: " . $playersOnline;

It should look like this:
PHP:
<?php
$online_otservlist = 0;
try {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://otarchive.com/server/6452daeb8fe898282d5263a7");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return data inplace of echoing on screen
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); // Skip SSL Verification
    curl_setopt($ch, CURLOPT_ENCODING , "");
    $site = curl_exec($ch);
    curl_close($ch);
    preg_match('/Informed Players (\d+) \(\d+\)/', $site, $matches);
    // preg_match('/There are: <strong>([0-9]*)<\/strong>/', $site, $matches);
    $doc = new DOMDocument();
    @$doc->loadHTML($site);

    $xpath = new DOMXPath($doc);

    // Encontre o elemento <th> com o texto "Jogadores Informados"
    $thElement = $xpath->query('//th[contains(text(), "Jogadores informados")]')->item(0);
    if ($thElement) {
        // Encontre o elemento <td> irmão de <th> que contém o número de jogadores online
        $tdElement = $thElement->nextSibling;
        if ($tdElement && $tdElement->nodeName === 'td') {
            $playersOnlineText = $tdElement->nodeValue;
            //Use uma expressão regular para extrair apenas o número
            if (preg_match('/(\d+)/', $playersOnlineText, $matches)) {
                $jogadoresOnline = $jogos[1];
            }
        }
    }
    $online_otservlist = $correspondências[1];
} catch(Exceção $e) {}
$online_discord = 0;
tentar {
    $online_discord = json_decode(file_get_contents("https://discord.com/api/guilds/1136264192232525964/widget.json "))->presence_count;
} catch(Exceção $e) {}

$resposta = array(
    "online" => "$online_otservlist Jogadores online",
    "discord_online" => $online_discord,
    "discord_link" => "https://discord.gg/t4ntS5p"
);
eco json_encode($resposta);
?>[/CÓDIGO]
[/QUOTE]
Ooh, sorry man! An oversight. Thanks 😃
 

Similar threads

Back
Top