Created
April 7, 2015 20:10
-
-
Save Danno040/ab6d813d62a25f3ed893 to your computer and use it in GitHub Desktop.
Extends Laravel's validator to check if a value is a "real" domain pointing to specific servers
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
Validator::extend('realdomain', function ($attribute, $value, $parameters) { | |
$domain = idn_to_ascii($value); | |
// Basic "is domain" check | |
if (filter_var('http://' . $domain, FILTER_VALIDATE_URL) === false) { | |
return false; | |
} | |
// Grab the A records and CNAMES | |
$records = dns_get_record($domain, DNS_ALL); | |
foreach($records as $record) { | |
if ($record['type'] == 'A') { | |
if ($record['ip'] == 'VALID_IP_ADDRESS') { | |
return true; | |
} | |
} elseif ($record['type'] == 'CNAME') { | |
if ($record['target'] == 'VALID_CNAME') { | |
return true; | |
} | |
} | |
} | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment