gpt4 book ai didi

php - 获取 header 响应代码

转载 作者:可可西里 更新时间:2023-11-01 12:24:59 27 4
gpt4 key购买 nike

这是我放在一起的 PHP 脚本的一部分。基本上,域($domain1)在表单中定义,并根据服务器的响应代码显示不同的消息。但是,我在让它工作时遇到问题。我只对 3 位数的响应代码感兴趣。

这是我目前所拥有的:

function get_http_response_code($domain1) {
$headers = get_headers($domain1);
return substr($headers[0], 9, 3);
foreach ($get_http_response_code as $gethead) {
if ($gethead == 200) {
echo "OKAY!";
} else {
echo "Nokay!";
}
}
}

最佳答案

$domain1 = 'http://google.com';

function get_http_response_code($domain1) {
$headers = get_headers($domain1);
return substr($headers[0], 9, 3);
}

$get_http_response_code = get_http_response_code($domain1);

if ( $get_http_response_code == 200 ) {
echo "OKAY!";
} else {
echo "Nokay!";
}

关于php - 获取 header 响应代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3408049/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com