라이브러리

[PHP] http_clear_last_response_headers - 저장된 HTTP 응답 헤더를 지웁니다.




PHP의 `http_clear_last_response_headers` 함수는 HTTP 요청의 마지막 응답 헤더를 삭제합니다. 이 함수는 PHP 7.2.0 버전부터 사용할 수 있습니다.

사용법


`http_clear_last_response_headers` 함수는 다음과 같이 사용할 수 있습니다.

#hostingforum.kr
php

http_clear_last_response_headers();



예제


다음 예제는 `http_clear_last_response_headers` 함수를 사용하여 HTTP 요청의 마지막 응답 헤더를 삭제하는 방법을 보여줍니다.

#hostingforum.kr
php

<?php



// HTTP 요청을 보냅니다.

$url = 'https://example.com';

$headers = array(

    'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',

);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);

curl_close($ch);



// 마지막 응답 헤더를 삭제합니다.

http_clear_last_response_headers();



// 마지막 응답 헤더를 확인합니다.

print_r(curl_getinfo($ch, CURLINFO_HEADER_OUT));



?>



참고


`http_clear_last_response_headers` 함수는 PHP 7.2.0 버전부터 사용할 수 있습니다. 이 함수는 HTTP 요청의 마지막 응답 헤더를 삭제합니다. 이 함수를 사용하면 HTTP 요청의 마지막 응답 헤더를 삭제할 수 있습니다.

예제 2


다음 예제는 `http_clear_last_response_headers` 함수를 사용하여 HTTP 요청의 마지막 응답 헤더를 삭제하는 방법을 보여줍니다. 이 예제에서는 `curl` 함수를 사용하여 HTTP 요청을 보냅니다.

#hostingforum.kr
php

<?php



// HTTP 요청을 보냅니다.

$url = 'https://example.com';

$headers = array(

    'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',

);

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);

curl_close($ch);



// 마지막 응답 헤더를 삭제합니다.

http_clear_last_response_headers();



// 마지막 응답 헤더를 확인합니다.

print_r(curl_getinfo($ch, CURLINFO_HEADER_OUT));



?>



예제 3


다음 예제는 `http_clear_last_response_headers` 함수를 사용하여 HTTP 요청의 마지막 응답 헤더를 삭제하는 방법을 보여줍니다. 이 예제에서는 `file_get_contents` 함수를 사용하여 HTTP 요청을 보냅니다.

#hostingforum.kr
php

<?php



// HTTP 요청을 보냅니다.

$url = 'https://example.com';

$headers = array(

    'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3',

);

$options = array(

    'http' => array(

        'method' => 'GET',

        'header' => implode("
", $headers),

    ),

);

$context = stream_context_create($options);

$response = file_get_contents($url, false, $context);



// 마지막 응답 헤더를 삭제합니다.

http_clear_last_response_headers();



// 마지막 응답 헤더를 확인합니다.

print_r(stream_get_meta_data($context)['wrapper_data']);



?>



참고


`http_clear_last_response_headers` 함수는 PHP 7.2.0 버전부터 사용할 수 있습니다. 이 함수는 HTTP 요청의 마지막 응답 헤더를 삭제합니다. 이 함수를 사용하면 HTTP 요청의 마지막 응답 헤더를 삭제할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 505 페이지

검색

게시물 검색