user3351236
user3351236

Reputation: 2538

PHP - retrieve token from header

What is the best way to retrieve token "r9QQ5koqJT_e8iKAqSM2hhj" from header.

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

Upvotes: 3

Views: 11262

Answers (1)

Mahmoud Tantawy
Mahmoud Tantawy

Reputation: 713

To read headers, in case you don't already know how to get them, check http://php.net/manual/en/function.getallheaders.php

To get the token, here is sample code

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

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

Upvotes: 7

Related Questions