Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php get bearer token from request

/** 
 * Get header Authorization
 * */
function getAuthorizationHeader(){
    $headers = null;
    if (isset($_SERVER['Authorization'])) {
        $headers = trim($_SERVER["Authorization"]);
    }
    else if (isset($_SERVER['HTTP_AUTHORIZATION'])) { //Nginx or fast CGI
        $headers = trim($_SERVER["HTTP_AUTHORIZATION"]);
    } elseif (function_exists('apache_request_headers')) {
        $requestHeaders = apache_request_headers();
        // Server-side fix for bug in old Android versions (a nice side-effect of this fix means we don't care about capitalization for Authorization)
        $requestHeaders = array_combine(array_map('ucwords', array_keys($requestHeaders)), array_values($requestHeaders));
        //print_r($requestHeaders);
        if (isset($requestHeaders['Authorization'])) {
            $headers = trim($requestHeaders['Authorization']);
        }
    }
    return $headers;
}

/**
 * get access token from header
 * */
function getBearerToken() {
    $headers = getAuthorizationHeader();
    // HEADER: Get the access token from the header
    if (!empty($headers)) {
        if (preg_match('/Bearers(S+)/', $headers, $matches)) {
            return $matches[1];
        }
    }
    return null;
}
Comment

PREVIOUS NEXT
Code Example
Php :: symfony 5 server start php bin cosleole 
Php :: api anaf 
Php :: laravel make model with migration 
Php :: magento 2 print php error 
Php :: php loop through array of objects 
Php :: php get class name without namespace from string 
Php :: laravel loop counter 
Php :: php add to array in loop 
Php :: validation not exists with this id laravel 
Php :: wordpress thumbnail 
Php :: select sql in php 
Php :: if object or array in php 
Php :: if is alphabet php 
Php :: laravel blade upper case 
Php :: php setinterval 
Php :: php failed to open stream: Permission denied iis 
Php :: laravel sortby varchar date 
Php :: Delete an array in multidimensional array php 
Php :: delete all cookies in php 
Php :: target class usercontroller does not exist. in laravel 8 
Php :: laravel select default old value 
Php :: eloquent whereraw 
Php :: symfony datetime now 
Php :: item count in cart quantitiy woocommerce 
Php :: php stop execution 
Php :: how to search by sku woocommerce 
Php :: php remove duplicates from multidimensional array 
Php :: laravel create text file 
Php :: storage in laravel 
Php :: ubuntu laravel storage permission 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =