How can you check if a website exists using PHP?
To check if a website exists using PHP, you can use the `get_headers` function to send a HEAD request to the website URL and check the response code. If the response code is 200, then the website exists.
function websiteExists($url){
$headers = @get_headers($url);
if($headers && strpos($headers[0], '200')){
return true;
} else {
return false;
}
}
// Example usage
$url = 'https://www.example.com';
if(websiteExists($url)){
echo 'Website exists';
} else {
echo 'Website does not exist';
}