Created
July 7, 2016 09:52
-
-
Save sdennler/e69f00cd432d6060fa650223d059fa65 to your computer and use it in GitHub Desktop.
Checks a CSV list of links for header like X-Frame-Options and outputs a CSV whit added header information.
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 | |
$csv = fopen('in.csv', 'r'); | |
$out = fopen('out.csv', 'w'); | |
$number = 0; | |
while($line = fgetcsv($csv, 0, ',', '"')){ | |
echo "Processing Line $number: ".var_export($line[2], true)."\n"; | |
$url = array_pop($line); // Last field should contain the URL to check | |
if(strpos($url, 'http') > -1){ | |
$link = @fopen($url, 'r'); | |
if(!$link) { | |
$error = error_get_last(); | |
echo "Error reading URL: ".$error['message']."\n"; | |
$line[] = 'ERROR: '. $error['message']; | |
} | |
else { | |
$meta = stream_get_meta_data($link); | |
fclose($link); | |
$headers = array(); | |
foreach ($meta['wrapper_data'] as $response) { | |
if(strpos(strtolower($response), 'content-security-policy') > -1 || strpos(strtolower($response), 'x-frame-options') > -1){ | |
$headers[] = $response; | |
} | |
} | |
$line[] = implode(' | ', $headers); | |
} | |
} | |
else { | |
$line[] = $number == 0 ? 'header' : ''; | |
} | |
$line[] = $url; | |
fputcsv($out, $line, ',', '"'); | |
$number++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment