How can PHP be used to determine the availability of a website and display it as online or offline?
To determine the availability of a website using PHP, you can use the `get_headers()` function to check the response headers of the website. If the response code is 200, it means the website is online, otherwise it is offline.
$url = 'https://www.example.com';
$headers = @get_headers($url);
if ($headers && strpos($headers[0], '200')) {
echo 'Website is online';
} else {
echo 'Website is offline';
}
Keywords
Related Questions
- What are some potential pitfalls to avoid when implementing URL rewriting in PHP?
- How can fopen() be used in PHP to delete the contents of a file while keeping the file itself intact?
- How can PHP be used to dynamically populate a second dropdown menu based on the selection in the first dropdown menu without reloading the page?