繁体   English   中英

Joomla不发送自定义标题

[英]Joomla Not Sending Custom Header

所以我有一个服务器到服务器的应用程序。 服务器1,域1上的PHP脚本在页面中设置了一个自定义标头(授权:承载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

从setheader调用中删除双点:

$app = JFactory::getApplication();
$app->setHeader('Authorization', 'Bearer 123456789');
$app->sendHeaders();

感谢您的建议Yoleth。 我对此进行了测试,并得到了相同的结果。

但是我发现了问题。 设置标题的Joomla网站正在使用名为“网站锁”的组件。 这类似于使网站脱机,但对开发人员而言具有一些不错的功能。

基本上,Site Lock阻止了该页面的提供,只是从锁定页面返回标头(应如此)。 我不知道为什么我没有更早看到它。 有时就是看不见树木的森林!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM