1

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

Penny
  • 824
  • 1
  • 14
  • 31
  • Probably something to do with your server configuration. – scrowler Dec 09 '14 at 09:44
  • Your server don't send Content-Length so there is nothing to get – mleko Dec 09 '14 at 09:50
  • There is no such header... https://requestable.pieterhordijk.com/4rCuvc – PeeHaa Dec 09 '14 at 10:11
  • @PeeHaa When i use get_headers for this web page i get the result as i have edited my question. – Penny Dec 09 '14 at 10:16
  • Yes, but that is not the domain you are trying to get... – PeeHaa Dec 09 '14 at 10:19
  • @PeeHaa Yes not the domain, However how does that change? its a webpage after all! Please Explain I did not get – Penny Dec 09 '14 at 10:23
  • If the server doesn't send the header there is absolutely nothing you can do besides doing an actual request and calculating the length yourself. You can show us the headers of other sites, but that has nothing to do with your actual problem. – PeeHaa Dec 09 '14 at 10:25
  • Please check this answer: [http://stackoverflow.com/questions/23844680/php-get-headers-not-working](http://stackoverflow.com/questions/23844680/php-get-headers-not-working) I think this can be help you. – Vijay Verma Dec 09 '14 at 10:35

2 Answers2

1

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.

Kouber Saparev
  • 7,637
  • 2
  • 29
  • 26
  • Yes Content-Length I got for one page. – Penny Dec 09 '14 at 10:06
  • If I dont get is there no other way by which I can get this? – Penny Dec 09 '14 at 10:09
  • You can do it by using [filesize()](http://php.net/manual/en/function.filesize.php) and passing an `URL` to it. But also mind that it will create some network overhead as it is going to fetch the entire page to get its length. – Kouber Saparev Dec 09 '14 at 10:13
  • filesize() when used gives an error `Warning: filesize(): stat failed for http://www.ecomexpomelbourne.com.au/sponsors/ in D:\xampp` – Penny Dec 09 '14 at 10:19
  • @KouberSaparev, _You can do it by using filesize()_ - only if `http://` wrapper [is supported](http://php.net/manual/en/wrappers.php) – vladkras Dec 09 '14 at 10:19
  • 1
    @Penny, look at the second comment under the function description for filesize() in the link I gave you above. – Kouber Saparev Dec 09 '14 at 10:43
  • @KouberSaparev Thanks it gave me some value. But it shows lot of difference when compared with value in firebug tool! – Penny Dec 09 '14 at 10:54
0

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

vladkras
  • 16,483
  • 4
  • 45
  • 55