If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
get_headers() function , किसी HTTP request के लिए server द्वारा send किये गए सभी headers return करता है।
get_headers(string $url , int $format = 0 , resource $context = ? );
string $url | required : targeted URL . हालाँकि URL valid होना चाहिए नहीं तो error आएगी।
int $format = 0 | optional : non - zero value pass करने पर Associative Array return होता है। otherwise headers का Indexed Array return होता है।
resource $context = ? | optional : valid context resource जो कि stream_context_create() के द्वारा create किया गया हो।
Return Value : यह headers का indexed or associative array return करता है , fail होने पर false .
File : php_get_headers.php
<?php
echo "<pre>";
print_r(get_headers("https://www.google.com"));
print_r(get_headers("https://www.google.com", true));
echo "</pre>";
?>
Array ( [0] => HTTP/1.1 200 OK [1] => Date: Wed, 19 May 2021 04:12:44 GMT [2] => Expires: -1 [3] => Cache-Control: private, max-age=0 [4] => Content-Type: text/html; charset=ISO-8859-1 [5] => P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info." [6] => Server: gws [7] => X-XSS-Protection: 0 [8] => X-Frame-Options: SAMEORIGIN [9] => Set-Cookie: 1P_JAR=2021-05-19-04; expires=Fri, 18-Jun-2021 04:12:44 GMT; path=/; domain=.google.com; Secure [10] => Set-Cookie: NID=216=B5qYFzMXb81sl3Mxg1Z3dRvjp9QfIeMwQO2mWYN_mWrpld7kv17foeISMkRe-1UTqGMbd08UzDQjS4TDZgyeC7CVbJIvoEls-jjVbjD_KsaHJ407NBB1Qe5banAEeB0QOHjT1GIeJlcx1Y3og7-XDFHS7QjxZX5QVrXj5MBkzFM; expires=Thu, 18-Nov-2021 04:12:44 GMT; path=/; domain=.google.com; HttpOnly [11] => Alt-Svc: h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" [12] => Accept-Ranges: none [13] => Vary: Accept-Encoding [14] => Connection: close [15] => Transfer-Encoding: chunked ) Array ( [0] => HTTP/1.1 200 OK [Date] => Wed, 19 May 2021 04:12:45 GMT [Expires] => -1 [Cache-Control] => private, max-age=0 [Content-Type] => text/html; charset=ISO-8859-1 [P3P] => CP="This is not a P3P policy! See g.co/p3phelp for more info." [Server] => gws [X-XSS-Protection] => 0 [X-Frame-Options] => SAMEORIGIN [Set-Cookie] => Array ( [0] => 1P_JAR=2021-05-19-04; expires=Fri, 18-Jun-2021 04:12:45 GMT; path=/; domain=.google.com; Secure [1] => NID=216=E3q4j_SZxOKBtbTEx-nyEDzbJtrNz7Vjkys9QAz-18Fonm7slDITVhwyYXYBdhf9ANpdm5lZdHbh5-vsnv7AXgO05lLtMTVMjChxEe7uNR_gddwNYCav5JHz6tS-kIvy7udMN4dnmoUh_ntdApO85OMHrTPXq1ZgH5wPnx1nxAk; expires=Thu, 18-Nov-2021 04:12:45 GMT; path=/; domain=.google.com; HttpOnly ) [Alt-Svc] => h3-29=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43" [Accept-Ranges] => none [Vary] => Accept-Encoding [Connection] => close [Transfer-Encoding] => chunked )