Created
September 10, 2021 10:13
-
-
Save millipedia/85782017a7ab45bbadfa8f0bc9867ab6 to your computer and use it in GitHub Desktop.
Revisions
-
millipedia created this gist
Sep 10, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ <?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>';