wp_get_http_headers( string $url, bool $deprecated = false ): WpOrgRequestsUtilityCaseInsensitiveDictionary|false

Retrieves HTTP Headers from URL.

Parameters

$urlstringrequired
URL to retrieve HTTP headers from.
$deprecatedbooloptional
Not Used.

Default:false

Return

WpOrgRequestsUtilityCaseInsensitiveDictionary|false Headers on success, false on failure.

Source

function wp_get_http_headers( $url, $deprecated = false ) {
	if ( ! empty( $deprecated ) ) {
		_deprecated_argument( __FUNCTION__, '2.7.0' );
	}

	$response = wp_safe_remote_head( $url );

	if ( is_wp_error( $response ) ) {
		return false;
	}

	return wp_remote_retrieve_headers( $response );
}

Changelog

VersionDescription
1.5.1Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Use the returned class’ (WpOrgRequestsUtilityCaseInsensitiveDictionary) methods to get usable data:

    $response = wp_get_http_headers( 'https://wordpress.org' );
    print_r( $response->getAll() );

    Array
    (
    [server] => nginx
    [date] => Sat, 09 Sep 2023 04:27:52 GMT
    [content-type] => text/html; charset=UTF-8
    [vary] => Accept-Encoding
    [strict-transport-security] => max-age=3600
    [x-olaf] => ⛄[link] => Array
    (
    [0] => ; rel=”https://api.w.org/”
    [1] => ; rel=”alternate”; type=”application/json”
    [2] => ; rel=shortlink
    )

    [x-frame-options] => SAMEORIGIN
    [content-encoding] => gzip
    [x-nc] => EXPIRED ord 1
    )

    print_r($response->offsetGet('server'));

    nginx

You must log in before being able to contribute a note or feedback.