2019-09-26 17:28:08 1803次浏览 2条回答 0 悬赏 10 金钱

PHP 如何在 Header 头里面传输信息?

最佳答案

  • Cathay 发布于 2019-09-30 23:37 举报

    希望这段代码对你有所帮助。源码文件:
    Response.php

        /**
         * Sends the response headers to the client.
         */
        protected function sendHeaders()
        {
            if (headers_sent($file, $line)) {
                throw new HeadersAlreadySentException($file, $line);
            }
            if ($this->_headers) {
                foreach ($this->getHeaders() as $name => $values) {
                    $name = str_replace(' ', '-', ucwords(str_replace('-', ' ', $name)));
                    // set replace for first occurrence of header but false afterwards to allow multiple
                    $replace = true;
                    foreach ($values as $value) {
                        header("$name: $value", $replace);
                        $replace = false;
                    }
                }
            }
            $statusCode = $this->getStatusCode();
            header("HTTP/{$this->version} {$statusCode} {$this->statusText}");
            $this->sendCookies();
        }
    
您需要登录后才可以回答。登录 | 立即注册
PHP学院的中学生
副总裁

PHP学院的中学生

注册时间:2018-10-23
最后登录:2024-04-07
在线时长:168小时1分
  • 粉丝29
  • 金钱4730
  • 威望30
  • 积分6710

热门问题