How can we check if URL is only the domain.
http://www.google.pl TRUE
http://www.google.pl/aaaaa FALSE
http://www.google.pl/aaaaa?ahaha=22 FALSE
I want to check if user only write the domain.
How can we check if URL is only the domain.
http://www.google.pl TRUE
http://www.google.pl/aaaaa FALSE
http://www.google.pl/aaaaa?ahaha=22 FALSE
I want to check if user only write the domain.
Use SERVER_NAME.
$url = $_SERVER['SERVER_NAME']; //Outputs the base url www.example.com
if($url == $mydomain){
//do something
}
parse_url can turn a URL-string ($url) into an array, but can also return parts of that URL. Using that feature we can reconstruct a URL-string that consists only of a scheme and a host. If this matches with the original URL-string ($url), than it must be a domain-only URL
$url = "https://example.com/blabla";
if (parse_url($url, PHP_URL_SCHEME) . '://' . parse_url($url, PHP_URL_HOST) == $url) {
echo "host only";
} else {
echo "more than that";
}