Reputation: 147
I made a form where user post their product information and data. Information contain full name of the product, Manufacturers Name, Contact Address and Link of Manufacturers site. Now i know for validate the link we can use FILTER_VALIDATE_URL
php variable. Now the thing is let suppose if someone posted https://www.google.com?page=bla+bla
, This FILTER_VALIDATE_URL
variable allows the url after .com or .net or .org
etc. It means php variable allows the path here and URL validation not end here.
What i want is Do you guys know any php variable the can only validate the URL from https to .com or .net or .org
etc and not allow the path like the example above.
EDIT: The list updates in the pdf format which can than be further access to whole company. Lets someone douche trying to put the wrong link thats why i need validation for the link.
Upvotes: 1
Views: 72
Reputation: 90
parse_url returns an array containing the url's components. e.g.
var_dump( parse_url('https://www.google.com?page=bla+bla') );
outputs
array (size=3)
'scheme' => string 'https' (length=5)
'host' => string 'www.google.com' (length=14)
'query' => string 'page=bla+bla' (length=12)
you can then validate the host
array element and ignore the query
$clean_url = parse_url($url)['host'];
Upvotes: 1