Skip to content

Instantly share code, notes, and snippets.

@zeshanshani
Created March 9, 2019 08:23
Show Gist options
  • Save zeshanshani/54ad41cd40eaf319c66bd1d8e2e839bb to your computer and use it in GitHub Desktop.
Save zeshanshani/54ad41cd40eaf319c66bd1d8e2e839bb to your computer and use it in GitHub Desktop.
This function checks if the provided URL is of external site or not. Returns boolean.
<?php // do not copy this line.
/**
* Is External
*
* This function checks if the provided URL is external or not.
*
* Author URL: https://zeshanahmed.com/
*
* @param string $url URL to be checked
* @author Zeshan Ahmed
* @return boolean
*/
function is_external( $url ) {
$url_parts = parse_url( $url );
return ! empty( $url_parts['host']) && strcasecmp( $url_parts['host'], $_SERVER['HTTP_HOST'] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment