Skip to content

Instantly share code, notes, and snippets.

@thistehneisen
Created February 25, 2021 07:43
Show Gist options
  • Save thistehneisen/9f1f09b6b852f4ff7c4741795c0682b6 to your computer and use it in GitHub Desktop.
Save thistehneisen/9f1f09b6b852f4ff7c4741795c0682b6 to your computer and use it in GitHub Desktop.
Simple PHP script to verify HTTP response codes from domain list
<?php
$addresses = file('addresses.txt', FILE_IGNORE_NEW_LINES);
$responding = [];
foreach ($addresses as $address) {
if ($url = parse_url($address)) {
if (!isset($url['scheme'])) {
$address = 'http://' . $address;
}
}
if (!filter_var($address, FILTER_VALIDATE_URL)) {
print($address . ' doesn\'t qualify as an valid URL').PHP_EOL;
continue;
}
$ch = curl_init($address);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT,4);
$output = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 0) {
print($address . ' has HTTP code: ' . $httpCode) . PHP_EOL;
if (in_array($httpCode, [301, 302])) {
$address = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
print('=> ' . $address).PHP_EOL;
}
$responding[$httpCode][] = $address;
}
file_put_contents('result.txt', print_r($responding, true));
curl_close($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment