Fetching custom Authorization header from incoming PHP request

前端 未结 5 568
春和景丽
春和景丽 2020-12-04 19:47

So I\'m trying to parse an incoming request in PHP which has the following header set:

Authorization: Custom Username

Simple question: how

5条回答
  •  春和景丽
    2020-12-04 20:03

    For token based auth:

      $token = null;
      $headers = apache_request_headers();
      if(isset($headers['Authorization'])){
        $matches = array();
        preg_match('/Token token="(.*)"/', $headers['Authorization'], $matches);
        if(isset($matches[1])){
          $token = $matches[1];
        }
      } 
    

提交回复
热议问题