PHP scripts and programs for Beginner to Master

php programs, php ready to use scripts & functions, css tutorials, html, javascripts, ajax examples for Beginner to Master

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

I'm reading: check whether the url exists or not in phpTweet this!

0 comments:

Post a Comment