Skip to content

Instantly share code, notes, and snippets.

@M0NsTeRRR
Last active March 21, 2021 10:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save M0NsTeRRR/fe4f638f61409845fce3ff8f8314bfa1 to your computer and use it in GitHub Desktop.
Save M0NsTeRRR/fe4f638f61409845fce3ff8f8314bfa1 to your computer and use it in GitHub Desktop.
Get players bans on steam from steamID32, SteamID64 or Steam custom URL with steam API
<?php
// PHP >= 7
// You must add and enable CURL on your webserver
/**
* GET_SteamAPI
*
* @param string $endpoint http endpoint of Steam API
* @param string $steam_api_key your Steam API key
* @param string $parameters parameters for your request
*
* @return array body contains an array of requested data and http_code contain the http code of the request
*/
function GET_SteamAPI($endpoint, $steam_api_key, $parameterQuery = '')
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://api.steampowered.com/' . $endpoint . '?key='. $steam_api_key . $parameterQuery,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true,
CURLOPT_HEADER => true,
CURLOPT_SSL_VERIFYPEER => false
));
$output = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($output, 0, $header_size);
$body = json_decode(substr($output, $header_size));
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
return (array) array("body" => $body, "http_code" => $httpcode);
}
/**
* steamID32ToSteamID64
*
* @param string $steamID steamID32 of steam player
*
* @return string SteamID64
*/
function steamID32ToSteamID64($steamID)
{
$parts = explode(':', str_replace('STEAM_', '', $steamID));
$universe = (int)$parts[0];
$universe = $universe == 0 ? 1 : $universe;
$steamID = ($universe << 56) | (1 << 52) | (1 << 32) | ((int)$parts[2] << 1) | (int)$parts[1];
return $steamID;
}
/**
* steamCustomURLToSteamID64
*
* @param string $steamCustomURL custom URL of steam player
*
* @return string SteamID64
*/
function steamCustomURLToSteamID64($steam_api_key, $steamCustomURL)
{
return (array) GET_SteamAPI('ISteamUser/ResolveVanityURL/v0001/', $steam_api_key, '&vanityurl=' . $steamCustomURL);
}
/**
* checkBan
*
* @param string $steam_api_key
* @param string $steamids Comma-delimited list of SteamIDs
*
* @return array body contains an array of players and http_code contain the http code of the request
*/
function checkBan($steam_api_key, $steamids)
{
return (array) GET_SteamAPI('ISteamUser/GetPlayerBans/v1/', $steam_api_key, '&steamids=' . $steamids);
}
/**
* formatSteamIDs
*
* @param string $steam_api_key
*
* @return string Comma-delimited list of SteamIDs
*/
function formatSteamIDs($steam_api_key, $steamIDs)
{
$formattedSteamIDs = '';
foreach ($steamIDs as $steamID)
{
$formattedSteamIDs .= empty($formattedSteamIDs) ? "" : ",";
switch($steamID)
{
// SteamID32
case (preg_match("~^STEAM_0:[01]:[0-9]{7,8}$~", $steamID) ? true : false):
$formattedSteamIDs .= steamID32ToSteamID64($steamID);
break;
// SteamID64
case (preg_match("~^(https://steamcommunity\.com/profiles/[0-9/]{17})|([0-9]{17})$~", $steamID) ? true : false):
$formattedSteamIDs .= $steamID;
break;
// SteamCustomURL
case (preg_match("~^(https://steamcommunity\.com/id/[a-zA-Z0-9/]{1,})|([a-zA-Z0-9]{1,})$~", $steamID) ? true : false):
$steamID = preg_match("~^https://steamcommunity\.com/id/[a-zA-Z0-9/]{1,}$~", $steamID) ? str_replace("https://steamcommunity.com/id/", "", substr($steamID, 0, -1)) : $steamID;
$formattedSteamIDs .= steamCustomURLToSteamID64($steam_api_key, $steamID)["body"]->response->steamid;
break;
// Default
default:
$formattedSteamIDs .= $steamID;
break;
}
}
return (string) $formattedSteamIDs;
}
// [EXAMPLE BELOW]
// Scrappy test without try/catch etc... it's just a show case
// config (put your steam api key -> https://steamcommunity.com/dev/apikey)
$steam_api_key = "";
// Array of steamID
$steamIDs = [
"STEAM_0:0:75536491",
"https://steamcommunity.com/profiles/76561198111338710",
"76561198111338710",
"https://steamcommunity.com/id/LESMonster/",
"LESMonster"
];
// Format steamID if needed
$formattedSteamIDs = formatSteamIDs($steam_api_key, $steamIDs);
// Get players bans
$result = checkBan($steam_api_key, $formattedSteamIDs);
foreach ($result["body"]->players as $player)
{
echo "STEAM ID : <span style='color: blue'>" . $player->SteamId . "</span><br>"
. "Community Banned : " . $player->CommunityBanned . "<br>"
. "VAC Banned : " . $player->VACBanned . "<br>"
. "Number Of VAC Bans : <span style='color: red'>" . $player->NumberOfVACBans . "</span><br>"
. "Days Since Last Ban : " . $player->DaysSinceLastBan . "<br>"
. "Number Of Game Bans : " . $player->NumberOfGameBans . "<br>"
. "Economy Ban : " . $player->EconomyBan . "<br>"
. "<br>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment