Skip to content

Instantly share code, notes, and snippets.

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 eugene-ilyin/358e3786a547321adf91 to your computer and use it in GitHub Desktop.
Save eugene-ilyin/358e3786a547321adf91 to your computer and use it in GitHub Desktop.
Drupal check that url is really external
/**
* Check url for external property.
*/
function module_url_is_external($path) {
global $base_url;
$url_host = parse_url($path);
if (empty($url_host['host']) && empty($url_host['scheme'])) {
return FALSE;
} else {
if ($url_host['scheme'] . '://' . $url_host['host'] === substr($base_url, 0, strlen($url_host['scheme'] . '://' . $url_host['host']))) {
return FALSE;
}
}
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment