Site icon Nabtron

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 />”;
}

Exit mobile version