Piifafa
Member
- Joined
- Apr 16, 2023
- Messages
- 67
- Reaction score
- 16
I see that many are unable to correctly use the part that shows about discord and online player in the customer entry, I would like to share my solution, I don't know if there is anything better than that. But if so, leave it here so everyone can use it.
How did I get it to work?
How did I get it to work?
status.php
PHP:
<?php
$online_otservlist = 0;
try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ots-list.org/server/xxxxxxxxxxx");
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('/<\/span> ([0-9]*) \//', $site, $matches);
$online_otservlist = $matches[1];
} catch(Exception $e) {}
$online_discord = 0;
try {
$online_discord = json_decode(file_get_contents("https://discord.com/api/guilds/xxxxxxxxxxxxxxxx/widget.json"))->presence_count;
} catch(Exception $e) {}
$response = array(
"online" => "$online_otservlist Players online",
"discord_online" => $online_discord,
"discord_link" => "xxxxxxxxxxxxx"
);
echo json_encode($response);
?>