Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel 4: why is Request::header() not getting the specified header?

I'm trying to get a header value with:

Request::header('csrf_token')

though, my firebug says in the headers that I have the csrf_token set to baMDpF0yrfRerkdihFack1Sa9cchUk8qBzm0hK0C. In fact, I can get that csrf_token instead with a native php code:

getallheaders()['csrf_token']

Now the question is am I doing my XSRF-protection right? or maybe there is a flaw in that php code I did, that I really have to use buggy laravel 4 function

Request::header('csrf_token')

which returns nothing but blank. And I just missed something. maybe in my Laravel 4 configurations, etc?

P.S: I am using AngularJS, but maybe it does not matter what clientside I use. I have this link as my guide: How to send csrf_token() inside AngularJS form using Laravel API?

like image 608
Tyro Hunter Avatar asked Sep 03 '13 06:09

Tyro Hunter


People also ask

How would you read header value from a Laravel request?

Laravel provides many details in Illuminate\Http\Request class object. You can simply get headers details using headers() method. This will return all headers in array.

How do you make a custom header in Laravel?

getting a custom header in Laravel 5.8. request()->header('x_requested_with'); I would suggest using Accessing-From: admin which will add the apache header HTTP_ACCESSING_FROM . And you will be able to access it via the header function like this...

How can I get Http header in PHP?

Receiving the request header, the web server will send an HTTP response header back to the client. Read any request header: It can be achieved by using getallheaders() function. Example 2: It can be achieved by using apache_request_headers() function.


1 Answers

I solved the problem by removing the underscore '_' in csrf_token so it would be crsftoken instead.

Request::header('csrf_token'); // Not working

Request::header('csrftoken'); // Working!
like image 181
RSorensen Avatar answered Sep 21 '22 10:09

RSorensen