Created
June 29, 2018 14:09
-
-
Save thocell/a191f3d45ea1ccb863050ccf19f39dfb to your computer and use it in GitHub Desktop.
get header info by php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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