Can PHP be used to check if a website exists?

To check if a website exists using PHP, you can make a simple HTTP request to the website and check the response code. If the response code is in the 200 range, it means the website exists and is accessible. You can use PHP's `get_headers()` function to achieve this.

function websiteExists($url){
    $headers = get_headers($url);
    return stripos($headers[0], "200 OK") !== false;
}

// Example usage
$url = "https://www.example.com";
if(websiteExists($url)){
    echo "Website exists!";
} else {
    echo "Website does not exist.";
}