The get_headers() function returns all the headers sent by the server for an HTTP request.
PHP get_headers() Syntax
get_headers(string $url , int $format = 0 , resource $context = ? );
- string $url | required : targeted URL . However the URL must be valid otherwise an error will occur.
- int $format = 0 | Optional : Associative Array is returned on passing non – zero value. Otherwise an Indexed Array of headers is returned.
- resource $context = ? , optional : valid context resource created by stream_context_create() .
- Return Value: It returns an indexed or associative array of headers, failing which false.
PHP get_headers() Example
File : php_get_headers.php
<?php echo "<pre>"; print_r(get_headers("https://www.itsolutionstuck.com")); print_r(get_headers("https://www.itsolutionstuck.com", true)); echo "</pre>"; ?>
Result:
comming soon.....