<?php
function check_website_status($url) {
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
curl_close($handle);
if ($httpCode >= 200 && $httpCode < 300) {
return "Website is up and running.";
} else {
return "Website is down with status code $httpCode.";
}
}
// Example usage:
$url = "https://www.example.com";
$status = check_website_status($url);
echo $status;
?>
Kịch bản này định nghĩa một hàm check_website_status
lấy URL làm đầu vào và trả về thông báo cho biết trang web đang hoạt động hay không. Bạn có thể thay thế "https://www.example.com"
với URL của trang web bạn muốn kiểm tra.
Bình luận (0)
Chưa có bình luận nào ở đây, bạn có thể là người đầu tiên!