コード例 #1
0
 public static function request_headers()
 {
     if (function_exists("apache_request_headers")) {
         return new HTTP_Header(apache_request_headers());
     } elseif (extension_loaded("http")) {
         $headers = version_compare(phpversion("http"), "2.0.0", ">=") ? \http\Env::getRequestHeader() : http_get_request_headers();
         return new HTTP_Header($headers);
     }
     $headers = array();
     if (!empty($_SERVER["CONTENT_TYPE"])) {
         $headers["content-type"] = $_SERVER["CONTENT_TYPE"];
     }
     if (!empty($_SERVER["CONTENT_LENGTH"])) {
         $headers["content-length"] = $_SERVER["CONTENT_LENGTH"];
     }
     foreach ($_SERVER as $key => $value) {
         if (strpos($key, "HTTP_") !== 0) {
             continue;
         }
         $headers[str_replace("_", "-", substr($key, 5))] = $value;
     }
     return new HTTP_Header($headers);
 }
コード例 #2
0
ファイル: HttpHeader.php プロジェクト: pldin601/Predictions
 /**
  * @param string $key
  * @return mixed
  */
 protected function getValue($key)
 {
     return Env::getRequestHeader($key);
 }
コード例 #3
0
 /**
  * Parses the the HTTP request headers and returns an array containing
  * key value pairs. This method is slow, but provides an accurate
  * representation of the HTTP request.
  *
  *      // Get http headers into the request
  *      $request->headers = HTTP::request_headers();
  *
  * @return  HTTP_Header
  */
 public static function request_headers()
 {
     // If running on apache server
     if (function_exists('apache_request_headers')) {
         // Return the much faster method
         return new HTTP_Header(apache_request_headers());
     } elseif (extension_loaded('http')) {
         // Return the much faster method
         $headers = version_compare(phpversion('http'), '2.0.0', '>=') ? \http\Env::getRequestHeader() : http_get_request_headers();
         return new HTTP_Header($headers);
     }
     // Setup the output
     $headers = array();
     // Parse the content type
     if (!empty($_SERVER['CONTENT_TYPE'])) {
         $headers['content-type'] = $_SERVER['CONTENT_TYPE'];
     }
     // Parse the content length
     if (!empty($_SERVER['CONTENT_LENGTH'])) {
         $headers['content-length'] = $_SERVER['CONTENT_LENGTH'];
     }
     foreach ($_SERVER as $key => $value) {
         // If there is no HTTP header here, skip
         if (strpos($key, 'HTTP_') !== 0) {
             continue;
         }
         // This is a dirty hack to ensure HTTP_X_FOO_BAR becomes X-FOO-BAR
         $headers[str_replace('_', '-', substr($key, 5))] = $value;
     }
     return new HTTP_Header($headers);
 }