Skip to content

Instantly share code, notes, and snippets.

@Danno040
Created April 7, 2015 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danno040/ab6d813d62a25f3ed893 to your computer and use it in GitHub Desktop.
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
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