How to fetches all the headers sent by the server in response to a HTTP request in PHP

2 Answers

0 votes
/*
array get_headers ( string $url [, int $format = 0 ] )
*/  

$url = 'http://www.collectivesolver.com';

echo "<pre>" . print_r(get_headers($url), 1) . "</pre>";


/*
run:
  
Array
(
    [0] => HTTP/1.0 200 OK
    [1] => X-Powered-By: PHP/5.4.45
    [2] => Set-Cookie: PHPSESSID=2cjoijasd76wsdfshdnjm3; path=/
    [3] => Expires: Thu, 19 Nov 1981 08:52:00 GMT
    [4] => Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    [5] => Pragma: no-cache
    [6] => Set-Cookie: qa_key=2edtw3asdjfsdh76sdfstk41m11di; expires=Fri, 18-Dec-2015 09:57:15 
    [7] => Content-Type: text/html; charset=utf-8
    [8] => Vary: Accept-Encoding
    [9] => Date: Wed, 16 Dec 2015 09:57:15 GMT
    [10] => Accept-Ranges: bytes
    [11] => Server: LiteSpeed
    [12] => Connection: close
)

*/

 



answered Dec 16, 2015 by avibootz
0 votes
/*
array get_headers ( string $url [, int $format = 0 ] )
*/  

$url = 'http://www.collectivesolver.com';

echo "<pre>" . print_r(get_headers($url, 1), 1) . "</pre>";


/*
run:
  
Array
(
    [0] => HTTP/1.0 200 OK
    [X-Powered-By] => PHP/5.4.45
    [Set-Cookie] => Array
        (
            [0] => PHPSESSID=hotcna9sdfsdfg5hmk02; path=/
            [1] => qa_key=e6dnegcf65xi2; expires=Fri, 18-Dec-2015 10:02:27
        )

    [Expires] => Thu, 19 Nov 1981 08:52:00 GMT
    [Cache-Control] => no-store, no-cache, must-revalidate, post-check=0
    [Pragma] => no-cache
    [Content-Type] => text/html; charset=utf-8
    [Vary] => Accept-Encoding
    [Date] => Wed, 16 Dec 2015 10:02:27 GMT
    [Accept-Ranges] => bytes
    [Server] => LiteSpeed
    [Connection] => close

)

*/

 



answered Dec 16, 2015 by avibootz

Related questions

1 answer 210 views
1 answer 170 views
1 answer 235 views
...