How to check if a website url is valid – PHP

There are various ways of checking if a given variable of website url is valid or not. However most of they try to get content of the webpage or ping it etc. The way that i prefer to use is by fopen command in a function or separately.

Use this code to confirm or verify that the given website address is valid and then do any further task as per your requirement

//checking if the site exists by fopen, instead of file_get_contents to speed it up

$url = “http://nabtron.com/”; //your url goes in this place instead of nabtron.com

if (@fopen($url,”r”)) {
echo “<b>”.$url.”</b> is accessible<br />”;
}

hire best wordpress php css developer
Need Help? Hire me now!
I can help you in anything related to webdevelopment, including: HTML, CSS, PHP & MySql, WordPress (plugins & themes development, others), regular expressions, server management, etc.

4 comments on “How to check if a website url is valid – PHP

  1. Great post! Would you mind if I use some of the information from your entry? I will provide a link back to your site, of course.

Leave a Reply

Your email address will not be published.