Whenever it is required to get some input url from user then the first things comes is check whether that url is working and valid or it is not working.
Here is a simple function which can be used to verify the liveness of the url.
Just pass the url to this function and it will tell you whether the url is working and valid or invalid.
In the function "check_url" we are going to open the given url with "fopen".
If its opened then return true else return false.
Now we are going to use this function.
you can pass the url from the GET or POST method to the function.
Here we are going to specify it directly in the code.
So we are asking our code to open the url http://www.chaprak.com with our function.
so after execution it will show the message as
http://www.chaprak.com is a valid URL.
See its very simple to check the validity of the url in php.
Full source code to try is here -
If you have any ideas and suggestions to improve this function then comments are always welcome.
Dont forget to tell your friends about http://programming-in-php.blogspot.com
MAKNYOSS
8 years ago