PHP - 从标头中检索令牌

时间:2016-01-26 14:07:06

标签: php

检索令牌的最佳方法是什么?#9; r9QQ5koqJT_e8iKAqSM2hhj"来自标题。

Host: localhost
Authorization: Bearer r9QQ5koqJT_e8iKAqSM2hhj
Content-Type: application/json
X-Version: 1
Accept: application/json
Content-Length: 61

1 个答案:

答案 0 :(得分:2)

要阅读标题,如果您还不知道如何获取标题,请查看http://php.net/manual/en/function.getallheaders.php

要获取令牌,请参阅示例代码

<?php
if (substr($header, 0, 7) !== 'Bearer ') {
    return false;
}

return trim(substr($header, 7));