Skip to content

Instantly share code, notes, and snippets.

@thocell
Created June 29, 2018 14:09
Show Gist options
  • Save thocell/a191f3d45ea1ccb863050ccf19f39dfb to your computer and use it in GitHub Desktop.
Save thocell/a191f3d45ea1ccb863050ccf19f39dfb to your computer and use it in GitHub Desktop.
get header info by php
function getFileInfo($url){
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 3 );
curl_exec( $ch );
$headerInfo = curl_getinfo( $ch );
curl_close( $ch );
return $headerInfo;
}
function get_headers_curl($url){
$curl = curl_init();
curl_setopt_array( $curl, array(
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 3,
CURLOPT_URL => $url));
$headers = explode( "\n", curl_exec($curl));
curl_close($curl);
return $headers;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment