首页›HTTP 响应›sendHeader 头部发送
sendHeader 头部发送
final 方法,输出状态行与全部响应头
发送顺序
| # | 头部 | 格式 |
|---|---|---|
| 1 | 状态行 | HTTP/1.1 {STATUS_CODE} {状态文案} |
| 2 | Date | Date:{gmdate("D,dMYH:i:sT")} |
| 3 | Content-Type | Content-Type:{content_type} |
| 4 | Content-Length | Content-Length:{strlen(stream)}(chunked 模式跳过) |
| 5 | Connection | Connection: close(chunked 模式跳过) |
| 6 | 自定义头 | 遍历 $_headers 逐个 header("k: v") |
代码要点
final function sendHeader(){
$statusmsg = self::HTTP_STATUS_CODES[$this->STATUS_CODE];
header("HTTP/1.1 {$this->STATUS_CODE} {$statusmsg}");
header("Date:".gmdate("D,dMYH:i:sT"));
header("Content-Type:{$this->content_type}");
if($this->__is_chunked){
// 切片模式不发送 Content-Length / Connection
}else{
header("Content-Length: " . strlen($this->stream));
header("Connection: close");
}
foreach ($this->_headers as $k=>$v){
header(sprintf("%s: %s",$k,$v));
}
}
KuoqiPHP v1.05 · 离线静态文档 · 界面基于 KuoqiUI ·
返回首页