这是我整理的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!";
}
}
}
Run Code Online (Sandbox Code Playgroud)
Mch*_*chl 22
$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!";
}
Run Code Online (Sandbox Code Playgroud)
如果你有PHP 5.4.0+,你可以使用http_response_code ()函数.例:
var_dump(http_response_code()); // int(200)
Run Code Online (Sandbox Code Playgroud)