function domain_301_redirect_check_domain in Domain 301 Redirect 7
Checks if a domain actually points to this site.
Parameters
string $domain: The domain to be checked.
Return value
bool Returns TRUE if the domain passes the check. FALSE otherwise.
2 calls to domain_301_redirect_check_domain()
- domain_301_redirect_admin_form_validate in ./
domain_301_redirect.admin.inc - Validation hook for Domain 301 Redirect Admin page.
- domain_301_redirect_cron in ./
domain_301_redirect.module - Implements hook_cron().
File
- ./
domain_301_redirect.module, line 194 - This module allows you to 301 redirect all domains to one specific domain.
Code
function domain_301_redirect_check_domain($domain) {
if (!empty($domain)) {
$retries = variable_get('domain_301_redirect_domain_check_retries', 3);
// Try to contact the redirect domain, if this fails, retry N times after a pause.
for ($i = 1; $i <= $retries; $i++) {
$time = time();
$hash = drupal_hmac_base64('domain_301_redirect_check_domain', $time . drupal_get_private_key() . drupal_get_hash_salt());
$result = drupal_http_request($domain . '/domain_301_redirect_check/' . $time);
if (!empty($result) && $result->data == $hash) {
return TRUE;
}
elseif ($i < $retries) {
// Pause between retries.
sleep(10);
}
}
}
return FALSE;
}