Reputation: 1
Is there a way to validate that an input URL is valid? For example, I've created a sheet that uses information from a different sheet we'll call 'A', but it changes to a new sheet we'll call 'B' every month. I've created an alert that requests the user to input a new URL at the beginning of the month, but how do I check to make sure it's a valid site before trying to pull data from it?
Upvotes: 0
Views: 92
Reputation: 785
Using regex you can write to file check in which will undergo testing of url and action is made if it changed. Then it is necessary to include this file to the page on which Url need to check.
Upvotes: 1
Reputation: 424
function ping($host, $port, $timeout) {
$tB = microtime(true);
$fP = fSockOpen($host, $port, $errno, $errstr, $timeout);
if (!$fP) { return "down"; }
$tA = microtime(true);
return round((($tA - $tB) * 1000), 0)." ms"; }
//Echoing it will display the ping if the host is up, if not it'll say
"down".
echo ping("www.google.com", 80, 10);
another :-
function urlExists($url=NULL)
{
if($url == NULL) return false;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<300){
return true;
} else {
return false;
}
}
Upvotes: 0