How to get custom header from HTTP response in Laravel 5?
Solution 1
Are you talking about get parameter or something? If so, use:
request()->accessing_from;
For header you should use:
request()->header('accessing_from');
The working solution for this was the answer (the last one) of daver
here:
Laravel get request header
Solution 2
Have you tried simple php?
<?php
// Replace XXXXXX_XXXX with the name of the header you need in UPPERCASE
$headerStringValue = $_SERVER['HTTP_XXXXXX_XXXX'];
Full answer: https://stackoverflow.com/a/541463/3548658
The docs says: https://laravel.com/api/5.3/Illuminate/Http/Request.html#method_header
use Request;
Request::header('accessing_from');
Comments
-
Caius almost 2 years
I'm trying to access a custom header from the Request in Laravel. The header name is "accessing_from". Listing all the headers in Laravel, gives me only the "standard ones", but the one that I've set isn't present in the list. Checking in the browser network tab I can see that the header gets sent. So I'm wondering how to access it from within Laravel.
I'm using Angular2 to make the request with the default http service.
The Laravel's $response->header() dump:
The web inspector's log:
-
Caius over 7 yearsno, I'm willing to get the exact header from the request, it's not a parameter
-
Alexey Mezenin over 7 yearsIf
request()->header('accessing_from');
doesn't show anything, you may want to readdaver
answer here. -
Caius over 7 yearsTrying to access the header with request()->header('accessing_from') returns a empty array :(
-
Caius over 7 years@HRLET, already tried that before, unfortunately none of both methods works.
-
Artistan over 4 yearsNeed to use
Accessing-From
- updated answer stackoverflow.com/a/59427256/372215