Exemplo n.º 1
0
 /**
  * @param string $identifier Either the player's Username or UUID.
  * @param int $timeout The length in seconds of the http request timeout.
  * @return MinecraftProfile|null Returns null if fetching of profile failed. Else returns completed user profile.
  */
 public static function getProfile($identifier, $timeout = 5)
 {
     if (strlen($identifier) <= 16) {
         $identifier = ProfileUtils::getUUIDFromUsername($identifier, $timeout);
         $url = "https://sessionserver.mojang.com/session/minecraft/profile/" . $identifier['uuid'];
     } else {
         $url = "https://sessionserver.mojang.com/session/minecraft/profile/" . $identifier;
     }
     // Use cURL instead of file_get_contents
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
     curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
     curl_setopt($ch, CURLOPT_URL, $url);
     // Execute
     $ret = curl_exec($ch);
     if (!empty($ret) && $ret != null && $ret != false) {
         $data = json_decode($ret, true);
         return new MinecraftProfile($data['name'], $data['id'], $data['properties']);
     } else {
         return null;
     }
 }
Exemplo n.º 2
0
 /**
  * @param string $identifier Either the player's Username or UUID.
  * @param int $timeout The length in seconds of the http request timeout.
  * @return MinecraftProfile|null Returns null if fetching of profile failed. Else returns completed user profile.
  */
 public static function getProfile($identifier, $timeout = 5)
 {
     if (strlen($identifier) <= 16) {
         $identifier = ProfileUtils::getUUIDFromUsername($identifier, $timeout)['uuid'];
     }
     $url = "https://sessionserver.mojang.com/session/minecraft/profile/" . $identifier;
     $ctx = stream_context_create(array('http' => array('timeout' => $timeout)));
     $ret = file_get_contents($url, 0, $ctx);
     if (isset($ret) && $ret != null && $ret != false) {
         $data = json_decode($ret, true);
         return new MinecraftProfile($data['name'], $data['id'], $data['properties']);
     } else {
         return null;
     }
 }