public static function curl($url, $method = 'GET', $data = false, $headers = false, $returnInfo = false, $auth = false)
    {
        $ch = curl_init();
        $info = null;
        if (strtoupper($method) == 'POST') {
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            if ($data !== false) {
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            }
        } else {
            if ($data !== false) {
                if (is_array($data)) {
                    $dataTokens = [];
                    foreach ($data as $key => $value) {
                        array_push($dataTokens, urlencode($key).'='.urlencode($value));
                    }
                    $data = implode('&', $dataTokens);
                }
                curl_setopt($ch, CURLOPT_URL, $url.'?'.$data);
            } else {
                curl_setopt($ch, CURLOPT_URL, $url);
            }
        }

        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);

        if ($headers !== false) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        }

        if ($auth !== false && strlen($auth['username']) > 0 && strlen($auth['password']) > 0) {
            curl_setopt($ch, CURLOPT_USERPWD, $auth['username'].':'.$auth['password']);
        }

        $contents = curl_exec($ch);
        if ($returnInfo) {
            $info = curl_getinfo($ch);
        }

        curl_close($ch);

        if ($returnInfo) {
            return ['contents' => $contents, 'info' => $info];
        }

        return $contents;
    }
public static function curl($url, $method = 'GET', $data = false, $headers = false, $returnInfo = false, $auth = false)
    {
        $ch = curl_init();
        $info = null;
        if (strtoupper($method) == 'POST') {
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            if ($data !== false) {
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            }
        } else {
            if ($data !== false) {
                if (is_array($data)) {
                    $dataTokens = [];
                    foreach ($data as $key => $value) {
                        array_push($dataTokens, urlencode($key).'='.urlencode($value));
                    }
                    $data = implode('&', $dataTokens);
                }
                curl_setopt($ch, CURLOPT_URL, $url.'?'.$data);
            } else {
                curl_setopt($ch, CURLOPT_URL, $url);
            }
        }

        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);

        if ($headers !== false) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        }

        if ($auth !== false && strlen($auth['username']) > 0 && strlen($auth['password']) > 0) {
            curl_setopt($ch, CURLOPT_USERPWD, $auth['username'].':'.$auth['password']);
        }

        $contents = curl_exec($ch);
        if ($returnInfo) {
            $info = curl_getinfo($ch);
        }

        curl_close($ch);

        if ($returnInfo) {
            return ['contents' => $contents, 'info' => $info];
        }

        return $contents;
    }
public static function curl ( $ url , $ method = 'GET' , $ data = false , $ headers = false , $ returnInfo = false , $ auth = false ) { $ ch = curl_init ( ) ; $ info = null ; if ( strtoupper ( $ method ) == 'POST' ) { curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; if ( $ data !== false ) { curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ data ) ; } } else { if ( $ data !== false ) { if ( is_array ( $ data ) ) { $ dataTokens = [ ] ; foreach ( $ data as $ key => $ value ) { array_push ( $ dataTokens , urlencode ( $ key ) . '=' . urlencode ( $ value ) ) ; } $ data = implode ( '&' , $ dataTokens ) ; } curl_setopt ( $ ch , CURLOPT_URL , $ url . '?' . $ data ) ; } else { curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; } } curl_setopt ( $ ch , CURLOPT_HEADER , false ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , true ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , 10 ) ; if ( $ headers !== false ) { curl_setopt ( $ ch , CURLOPT_HTTPHEADER , $ headers ) ; } if ( $ auth !== false && strlen ( $ auth [ 'username' ] ) > 0 && strlen ( $ auth [ 'password' ] ) > 0 ) { curl_setopt ( $ ch , CURLOPT_USERPWD , $ auth [ 'username' ] . ':' . $ auth [ 'password' ] ) ; } $ contents = curl_exec ( $ ch ) ; if ( $ returnInfo ) { $ info = curl_getinfo ( $ ch ) ; } curl_close ( $ ch ) ; if ( $ returnInfo ) { return [ 'contents' => $ contents , 'info' => $ info ] ; } return $ contents ; }
Make a Curl call.

@param string     $url        URL to curl
@param string     $method     GET or POST, Default GET
@param mixed      $data       Data to post, Default false
@param mixed      $headers    Additional headers, example: array ("Accept: application/json")
@param bool       $returnInfo Whether or not to retrieve curl_getinfo()
@param bool|array $auth       Basic authentication params. If array with keys 'username' and 'password' specified, CURLOPT_USERPWD cURL option will be set

@return array|string if $returnInfo is set to True, array is returned with two keys, contents (will contain response) and info (information regarding a specific transfer), otherwise response content is returned
Make a Curl call .