i am using the following function, this gives me the right output but ONLY it checks is URL pattern not correct Domain name…
filter_var($url, FILTER_VALIDATE_URL)
If i’ll enter the correct URL it displays it is valid but if i’ll enter the correct URL but not correct Domain name still it is displays the Valid URL..
Ex.
http://www.google.co.in
Output: Valid
http://www.google
output: Invalid
http://www.google.aa
output: Valid
In the third case it should be Invalid…
Any references would be appreciated…
Technically the second example should also be considered ‘valid’ and I am surprised that the filter does not validate it as correct. The third example is also correct. That method checks for syntax only and all three examples are actually correct syntax for a URL.
But you’re on a right path here, don’t get discouraged by what the filter check does. This is what I do to validate domains:
Do note that it is recommended not to outright ‘fail’ the user if the second step fails. Sometimes there are problems with DNS or the server and the request may fail despite being correct (even facebook.com can fail at times). As a result you should ‘allow’ the URL, but not do anything with it until you have double-checked it again at later time. Thus, if multiple checks fail then you should cancel the process.