【发布时间】:2017-01-19 14:54:49
【问题描述】:
所以我有一个服务器到服务器的应用程序。服务器 1、域 1 上的 PHP 脚本在页面中设置了一个自定义标头(授权:Bearer 123456789)。服务器 2,域 2 上的脚本使用 get_headers() 来读取标头。
当文件以本机方式提供时,一切正常。但是,当服务器 1 上的脚本包含在 Joomla 模块中时,get_headers() 不会检索自定义标头。
在这两种情况下,开发人员工具都会显示自定义标头,但还会显示一些与 get_headers() 返回的标头不同的标头。
如果加载了 Joomla,下面的代码使用 JFactory 设置标题,但使用 header() 的结果相同。 Joomla 只是没有传递自定义标题。
我不明白。有人知道这里发生了什么吗?它不是 SEF 或 htaccess 问题。
<?php
// Server 1
if(!class_exists("JFactory")){ // no Joomla
header('Authorization: Bearer 123456789');
} else { // Joomla framework loaded
$app = JFactory::getApplication();
$app->setHeader('Authorization: ', 'Bearer 123456789');
$app->sendHeaders();
}
服务器 2 上的代码:
<?php
// Server 2
$headers = get_headers("http://server1.com/");
foreach($headers as $header) {
echo $header ."<br/>";
}
原生服务时 get_headers() 的输出:
HTTP/1.1 200 OK
Date: Thu, 19 Jan 2017 12:44:35 GMT
Server: Apache
Authorization: Bearer 123456789
Content-Length: 0
Connection: close
Content-Type: text/html
Joomla 服务时 get_headers() 的输出:
HTTP/1.1 200 OK
Date: Thu, 19 Jan 2017 12:45:49 GMT
Server: Apache
Set-Cookie: 3c460b3da9ecb202e794816b4144c6ff=ja7mn4b4njov98lsv76kk8pvu2; path=/; HttpOnly
Vary: Accept-Encoding
Content-Length: 1264
Connection: close
Content-Type: text/html
开发者工具显示的原生标题:
Authorization: Bearer 123456789
Date: Thu, 19 Jan 2017 13:07:32 GMT
Server: Apache
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Content-Length: 0
Content-Type: text/html
200 OK
开发者工具显示的 Joomla 标头:
Pragma: no-cache
Date: Thu, 19 Jan 2017 12:19:24 GMT
Last-Modified: Thu, 19 Jan 2017 12:19:25 GMT
Server: Apache
Authorization: : Bearer 123456789
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: Keep-Alive
Keep-Alive: timeout=5, max=100
Content-Length: 76888
Expires: Wed, 17 Aug 2005 00:00:00 GMT
【问题讨论】: