pocketmine\utils\Utils::getURL PHP Method

getURL() public static method

GETs an URL using cURL
public static getURL ( $page, integer $timeout = 10, array $extraHeaders = [] ) : boolean | mixed
$page
$timeout integer default 10
$extraHeaders array
return boolean | mixed
    public static function getURL($page, $timeout = 10, array $extraHeaders = [])
    {
        if (Utils::$online === false) {
            return false;
        }
        $ch = curl_init($page);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge(["User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 PocketMine-MP"], $extraHeaders));
        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
        curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int) $timeout);
        curl_setopt($ch, CURLOPT_TIMEOUT, (int) $timeout);
        $ret = curl_exec($ch);
        curl_close($ch);
        return $ret;
    }

Usage Example

Example #1
0
 public function onRun()
 {
     $ch = curl_init("https://api.mojang.com/profiles/minecraft");
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([$this->username]));
     curl_setopt($ch, CURLOPT_AUTOREFERER, true);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0 PocketMine-MP", "Content-Type: application/json"));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_TIMEOUT, 3);
     $ret = json_decode(curl_exec($ch), true);
     curl_close($ch);
     if (!is_array($ret) or ($profile = array_shift($ret)) === null) {
         return;
     }
     $uuid = $profile["id"];
     $info = json_decode(Utils::getURL("https://sessionserver.mojang.com/session/minecraft/profile/{$uuid}", 3), true);
     if (!is_array($info)) {
         return;
     }
     $this->setResult($info);
 }
All Usage Examples Of pocketmine\utils\Utils::getURL