Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- // http://wiki.vg/Mojang_API
- $USERNAME = $_GET["username"];
- if (!isset($USERNAME))
- die("Username not set");
- $CACHED_SKIN = $_SERVER["DOCUMENT_ROOT"] . "/skincache/$USERNAME.png";
- // Get username UUID
- $curl = curl_init();
- curl_setopt_array($curl, array(
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_URL => "https://api.mojang.com/users/profiles/minecraft/$USERNAME",
- CURLOPT_USERAGENT => "Mine-imator",
- CURLOPT_CONNECTTIMEOUT => 10
- ));
- $response = curl_exec($curl);
- $response_parsed = json_decode($response);
- if (json_last_error() != JSON_ERROR_NONE)
- die("Could not find user");
- if (isset($response_parsed->{"error"}))
- {
- // Fetch from cache or throw error
- if ($response_parsed->{"error"} == "TooManyRequestsException" && file_exists($CACHED_SKIN))
- {
- header("Content-type: image/png");
- header("Content-Length: " . filesize($CACHED_SKIN));
- readfile($CACHED_SKIN);
- die("");
- }
- else
- die("UUID " . $response_parsed->{"error"} . ": " . $response_parsed->{"errorMessage"});
- }
- $uuid = $response_parsed->{"id"};
- // Get skin URL
- curl_setopt_array($curl, array(
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_URL => "https://sessionserver.mojang.com/session/minecraft/profile/" . $uuid,
- CURLOPT_USERAGENT => "Mine-imator",
- CURLOPT_CONNECTTIMEOUT => 10
- ));
- $response = curl_exec($curl);
- $response_parsed = json_decode($response);
- if (json_last_error() != JSON_ERROR_NONE)
- die("Could not find profile");
- if (isset($response_parsed->{"error"}))
- {
- // Fetch from cache or throw error
- if ($response_parsed->{"error"} == "TooManyRequestsException" && file_exists($CACHED_SKIN))
- {
- header("Content-type: image/png");
- header("Content-Length: " . filesize($CACHED_SKIN));
- readfile($CACHED_SKIN);
- die("");
- }
- else
- die("Profile " . $response_parsed->{"error"} . ": " . $response_parsed->{"errorMessage"});
- }
- $textures_data = $response_parsed->{"properties"}[0]->{"value"};
- $textures_parsed = json_decode(base64_decode($textures_data));
- if (json_last_error() != JSON_ERROR_NONE)
- die("Could not find texture data");
- $skin_url = $textures_parsed->{"textures"}->{"SKIN"}->{"url"};
- // Get skin image
- curl_setopt_array($curl, array(
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_URL => $skin_url,
- CURLOPT_USERAGENT => "Mine-imator",
- CURLOPT_CONNECTTIMEOUT => 10
- ));
- $data = curl_exec($curl);
- curl_close($curl);
- // Store in cache
- file_put_contents($CACHED_SKIN, $data);
- // Output skin
- header("Content-type: image/png");
- echo $data;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment