html - How To Check Whether A URL Is External URL or Internal URL With PHP? - Stack Overflow

PHOTO EMBED

Thu Nov 18 2021 03:49:50 GMT+0000 (UTC)

Saved by @richard

function isexternal($url) {
  $components = parse_url($url);
  if ( empty($components['host']) ) return false;  // we will treat url like '/relative.php' as relative
  if ( strcasecmp($components['host'], 'example.com') === 0 ) return false; // url host looks exactly like the local host
  return strrpos(strtolower($components['host']), '.example.com') !== strlen($components['host']) - strlen('.example.com'); // check if the url host is a subdomain
}
content_copyCOPY

https://stackoverflow.com/questions/22964579/how-to-check-whether-a-url-is-external-url-or-internal-url-with-php