get_headers() not returning Content-Length element

1.8k views Asked by At

Function get_headers() does not give an array with the same indexes when I make a change in domain. When and why does this occur?

I want Content-Length value for hundreds of domains. What changes do I need to make?

<?php
$url = 'http://www.ecomexpomelbourne.com.au/sponsors/';
echo "<pre>";
$domain_data[] = array();
$domain_data = get_headers( $url, 1 );
print_r($domain_data);
echo $domain_data['Last-Modified'];
?>

When used for current page url I get Content-Length index enter image description here

2

There are 2 answers

7
Kouber Saparev On BEST ANSWER

Sometimes the server just does not send the Content-length header, and you should expect and treat properly such cases, as there are such provisions described in RFC2616.

In some situations, when the page is dynamically generated (with PHP or other language), the length of the body is not known yet at the stage of the sending of headers, so there is no way for the server to generate proper Content-length header in advance. But there are also cases when the Content-length header is explicitly forbidden to be sent.

0
vladkras On

PWS is hopelessly outdated, use IIS instead. I'm not sure that PWS allows to configure response headers and I can't find any docs. This is what it sends now:

Cache-Control:private
Connection:keep-alive
Content-Encoding:gzip
Content-Type:text/html; charset=utf-8
Date:Tue, 09 Dec 2014 09:46:13 GMT
Expires:Mon, 08 Dec 2014 09:46:13 GMT
Server:PWS/8.1.20.5
Set-Cookie:www.ecomexpomelbourne.com.au_trackingData=; path=/
Transfer-Encoding:chunked
Vary:Accept-Encoding
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-Px:nc h0-s4.p1-hyd ( h0-s2.p6-lhr), nc h0-s2.p6-lhr ( origin)

there is no Content-length