I\'m using file_get_contents() to access a URL.
file_get_contents(\'http://somenotrealurl.com/notrealpage\');
If the URL is not real, it r
$url = 'https://www.yourdomain.com';
Normal
function checkOnline($url) {
$headers = get_headers($url);
$code = substr($headers[0], 9, 3);
if ($code == 200) {
return true;
}
return false;
}
if (checkOnline($url)) {
// URL is online, do something..
$getURL = file_get_contents($url);
} else {
// URL is offline, throw an error..
}
Pro
if (substr(get_headers($url)[0], 9, 3) == 200) {
// URL is online, do something..
}
Wtf level
(substr(get_headers($url)[0], 9, 3) == 200) ? echo 'Online' : echo 'Offline';