You are here

function cf_http_headers_errors in Common Functionality 7

Same name and namespace in other branches
  1. 7.2 modules/cf_http/cf_http.module \cf_http_headers_errors()

Search through an array of http errors for common 400 and 500 http codes.

Why: Custom php scripts need a straight-forward and easy way to pull data from another website. This is useful as an alternative to iframe and has advantages and disadvantages to iframes. An advantage is that this allows showing remote content even if the remote url is down (via caching). A disadvantage is that remote images and links need to be processed, updated, and possibly even manually cached.

Parameters

array $headers: An array of http headers.

array $function_history: (optional) An array of function names, ie: array('0' => 'my_function_name').

Return value

array An array with the following structure:

  • error_code: number representing the error code of the error found,

0 otherwise.

  • key: array key of the header with the error.
  • value: error information associated with the error code.
1 call to cf_http_headers_errors()
cf_http_parse_response in modules/cf_http/cf_http.module
Accepts and processes provided http content.

File

modules/cf_http/cf_http.module, line 160

Code

function cf_http_headers_errors(array &$headers, array $function_history = array()) {
  foreach ($headers as $key => &$value) {
    $matches = array();
    if (preg_match('/^([45]\\d\\d)\\s/i', $value, $matches) > 0) {
      return array(
        'error_code' => $matches[1],
        'key' => $key,
        'value' => &$value,
      );
    }
  }
  return array(
    'error_code' => 0,
    'key' => '',
    'value' => '',
  );
}