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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历