PMA\libraries\Util::httpRequest PHP Method

httpRequest() public static method

Creates HTTP request
public static httpRequest ( string $url, string $method, boolean $return_only_status = false, mixed $content = null, string $header = "" ) : mixed
$url string Url to send the request
$method string HTTP request method (GET, POST, PUT, DELETE, etc)
$return_only_status boolean If set to true, the method would only return response status
$content mixed Content to be sent with HTTP request
$header string Header to be set for the HTTP request
return mixed
    public static function httpRequest($url, $method, $return_only_status = false, $content = null, $header = "")
    {
        if (function_exists('curl_init')) {
            return Util::httpRequestCurl($url, $method, $return_only_status, $content, $header);
        } else {
            if (ini_get('allow_url_fopen')) {
                return Util::httpRequestFopen($url, $method, $return_only_status, $content, $header);
            }
        }
        return null;
    }

Usage Example

コード例 #1
0
 /**
  * Returns information with latest version from phpmyadmin.net
  *
  * @return object JSON decoded object with the data
  */
 public function getLatestVersion()
 {
     if (!$GLOBALS['cfg']['VersionCheck']) {
         return null;
     }
     // Get response text from phpmyadmin.net or from the session
     // Update cache every 6 hours
     if (isset($_SESSION['cache']['version_check']) && time() < $_SESSION['cache']['version_check']['timestamp'] + 3600 * 6) {
         $save = false;
         $response = $_SESSION['cache']['version_check']['response'];
     } else {
         $save = true;
         $file = 'https://www.phpmyadmin.net/home_page/version.json';
         $response = Util::httpRequest($file, "GET");
     }
     $response = $response ? $response : '{}';
     /* Parse response */
     $data = json_decode($response);
     /* Basic sanity checking */
     if (!is_object($data) || empty($data->version) || empty($data->releases) || empty($data->date)) {
         return null;
     }
     if ($save) {
         $_SESSION['cache']['version_check'] = array('response' => $response, 'timestamp' => time());
     }
     return $data;
 }
Util