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

Retrieves HTTP Headers from URL.


Parameters

$url string Required
URL to retrieve HTTP headers from.
$deprecated bool Optional
Not Used.

Default: false


Top ↑

Return

WpOrgRequestsUtilityCaseInsensitiveDictionary|false Headers on success, false on failure.


Top ↑

Source

File: wp-includes/functions.php. View all references

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 );
}


Top ↑

Changelog

Changelog
Version Description
1.5.1 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Sergio Scabuzzo

    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.