Created
September 10, 2021 10:13
-
-
Save millipedia/85782017a7ab45bbadfa8f0bc9867ab6 to your computer and use it in GitHub Desktop.
Display the http response of a list of URLs in a CSV
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 | |
/** | |
* | |
* Read a CSV file of URLS then use curl | |
* to check their http code and dump it all | |
* out in a table. | |
* | |
*/ | |
function page_404($url) { | |
$handle = curl_init($url); | |
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false); | |
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true); | |
/* Get the HTML or whatever is linked in $url. */ | |
$response = curl_exec($handle); | |
// get the httpcode of the repsonse. | |
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); | |
curl_close($handle); | |
return $httpCode; | |
} | |
echo '<html><body>'; | |
echo '<table><thead><tr><th>Page name</th><th>Response</th></tr></thead>'; | |
echo '<tbody>'; | |
if (($handle = fopen("urls_to_check.csv", "r")) !== FALSE) { | |
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { | |
$url=$data[0]; | |
$response=page_404($url); | |
echo '<tr>'; | |
echo '<td><a href="' . $url . '">' . $url .'</a></td>' . PHP_EOL; | |
echo '<td>' . $response . '</td>' . PHP_EOL; | |
echo '</tr>'; | |
} | |
fclose($handle); | |
}else{ | |
echo 'cant open urls_to_check.csv'; | |
} | |
echo '</tbody>'; | |
echo '</table>'; | |
echo '</body></html>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment