I have problem with this code:
$parse = parse_url($url); //$url is POST from input field
$urls = $parse['host'];
$domain = array('mydomain.com', 'mydomain.net');
if (!in_array($urls, $domain)) {
echo 'invalid URL';
}
Checking url, if not in array, give error if yes continue.... I see all similar thread but no one fix my problem.
P.S the problem is: Only give Invalid URL (in case when url is correct and in case when URL is wrong)
e.x url: mydomain.com/u/123-test need to be valid url
The main reason it is not working because your url doesn't contain the scheme
http(s)part. With thehttp(s)://, when you try toparse_url()it returns path value not the host valueDEMO: https://3v4l.org/nUCfH