dongzhuo3376 2017-11-17 09:57
浏览 8
已采纳

标头授权不在子域上工作

I have this function for Basic Authorization for my API.

private function authorize() {
    $headers = apache_request_headers();
    if(isset($headers['Authorization'])){
        if ($headers['Authorization'] == '14abd57ece42d9489aeae6e1865064751') { //'akif&&nadeem'
            return true;
        }
    }
    return false;
}

It works well on my API domain domain.com/api/actionname

But it does not work [Fails Authorization] when I try to access my API via a Sub Domain subdomain.domain.com/api/actionname

All code is correctly in place and API is performing perfectly without Authorization. Any idea how can I fix this?

Output of the Headers is as follows:

array(9) {
   ["Host"]=>
     string(24) "ultimate.bleupage.online"
     ["Connection"]=>
     string(10) "keep-alive"
     ["User-Agent"]=>
     string(115) "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
     ["Cache-Control"]=>
     string(8) "no-cache"
     ["Postman-Token"]=>
     string(36) "6330a309-ffcf-d72e-936a-bf10ff154d45"
     ["Accept"]=>
     string(3) "*/*"
     ["Accept-Encoding"]=>
     string(13) "gzip, deflate"
     ["Accept-Language"]=>
    string(26) "en-GB,en-US;q=0.8,en;q=0.6"
     ["Cookie"]=>
     string(36) "PHPSESSID=p2m0cc7sq7kn8fk2motvrobnn4"
   }
  • 写回答

1条回答 默认 最新

  • dqf67993 2017-11-17 11:06
    关注

    Try using some other parameter key than Authorization, like Auth, because sometimes Apache filters away the Authorization header you can get more info here Apache 2.4 + PHP-FPM and Authorization headers.

    which you can access, like this(with $_SERVER):

    $_SERVER['HTTP_AUTH']
    

    Or Like this(with apache_request_headers):

    apache_request_headers()['Auth'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计