Created
April 5, 2013 04:08
-
-
Save anonymous/5316554 to your computer and use it in GitHub Desktop.
Read the values from a cURL response header using regex.
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
<?php | |
define('COOKIE_FILE', 'cookie.txt'); | |
define('HEADER_REGEX', '#^.*?(\r?\n){2}#msi'); | |
$ch = curl_init(); | |
curl_setopt_array($ch, array( | |
CURLOPT_URL => $assetURL, | |
CURLOPT_POST => FALSE, | |
CURLOPT_HEADER => TRUE, | |
CURLOPT_BINARYTRANSFER => FALSE, | |
// CURLOPT_ENCODING => 'identity', | |
// CURLOPT_NOBODY => TRUE, | |
CURLOPT_COOKIESESSION => FALSE, | |
CURLOPT_COOKIEJAR => COOKIE_FILE, | |
CURLOPT_COOKIEFILE, COOKIE_FILE, | |
CURLOPT_RETURNTRANSFER => TRUE | |
)); | |
$assetResult = curl_exec($ch); | |
curl_close($ch); | |
unlink(COOKIE_FILE); | |
preg_match(HEADER_REGEX, $assetResult, $headerMatch); | |
$assetResult = str_replace($headerMatch[0], '', $assetResult); | |
$ignoreHeadersRegex = '#' . implode('|', $ignoreHeaders) . '#msi'; | |
$headers = preg_split('#\r?\n#', $headerMatch[0]); | |
foreach ($headers as $header) { | |
if (!preg_match($ignoreHeadersRegex, $header)) { | |
header($header); | |
// echo $header; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment