Change language

PHP Get_headers () function

Syntax:
get_headers ($url, $format, $context) 
Parameters:this function takes three parameter as above and described below:
  • $url:This is a required string parameter. It defines the target URL.
  • $format:This is an optional int parameter. If its value is nonzero, it will return an associative array, otherwise an indexed array.
  • $context:contains the actual resource context created by stream_context_create().
Example 1.In this example, the optional parameter $formatis not assigned.  
// Target URL $url = " https://www.engineerforengineer.org " ;  
// Get headers $headers = get_headers ( $url );  
// Print headings print_r ( $headers ); ?>
Output:
Array ([0] = > HTTP / 1.1 200 OK [1] = > Content-Type: text / html; charset = UTF-8 [2] = > Connection: close [3] = > Date: Sun, 19 May 2019 08:31:29 GMT [4] = > Server: Apache [5] = > Strict-Transport-Security: max-age = 3600; includeSubDomains [6] = > Cache- Control: s-maxage = 21600, max-age = 3, must-revalidate [7] = > Access-Control-Allow-Credentials: true [8] = > X-Frame-Options: DENY [9] = > X-Content-Type-Options: nosniff [10] = > Vary: Accept-Encoding, Cookie [11] = > X-Cache: Miss from cloudfront [12] = > Via: 1.1 aa0bb866c09b4e243eb9a97bcdb7fe32.cloudfront.net (CloudFront) [13] = > X-Amz-Cf-Id: QAOIIj4eBsrX0hyZ-UHjOtqA2dQePcLbEUZJ3KRohjsSPfcrcAFaiQ ==) 
Example 2:In this example, the value of the optional formatis set to a nonzero value.  
// Target URL $url = " https://www. engineerforengineer.org " ;  
// Get headers $headers = get_headers ( $url , 1);  
// Print headings print_r ( $headers ); ?>
Output:
Array ([0] = > HTTP / 1.1 200 OK [Content-Type] = > text / html; charset = UTF-8 [Connection] = > close [Date] = > Sun, 19 May 2019 08:35:47 GMT [Server] = > Apache [Strict-Transport-Security] = > max-age = 3600; includeSubDomains [Cache-Control] = > s-maxage = 21600, max-age = 3, must-revalidate [Access-Control-Allow-Credentials] = > true [X-Frame-Options] = > DENY [X-Content-Type-Options] = > nosniff [Vary] = > Accept- Encoding, Cookie [X-Cache] = > Miss from cloudfront [Via] = > 1.1 95d17b4d563934eb90636ad03f8f524e.cloudfront.net (CloudFront) [X-Amz-Cf-Id] = > se3QRyaWDeuQHI3GrisBoqMZAr4FJpresent)
    

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method