PHP: get_headers set temporary stream_context

前端 未结 3 1554
孤街浪徒
孤街浪徒 2020-12-19 05:51

I guess PHP\'s get_headers does not allow for a context, so I have to change the default stream context to only get the HEAD of a request. This causes some issues with othe

3条回答
  •  清酒与你
    2020-12-19 06:05

    I had a similar issue but I just used the file_get_contents function with the custom stream context instead.

    Here's how I implemented it:

    $options = array(
                   'http' => array(
                         'method' => 'HEAD',
                         'follow_location' => 0
                    )
               );
    
    $context = stream_context_create($options);
    
    @file_get_contents($url, NULL, $context);
    
    var_dump($http_response_header);
    

    Using this context only the headers will be fetched by file_get_contents and will populate the $http_response_header PHP variable.

提交回复
热议问题