I'm using tymondesigns/jwt-auth to create an api. And I need to get the URL of API request sender. So I wrote a middleware and used,
public function handle($request, Closure $next)
{
dd(request()->getHttpHost());
}
This gets the only api URL. And then I tried,
$request->header('referer');
I get an only a null value. Is there any way to achive this task?
I came across a similar question and found a solution. If I call my Laravel 8 API and look for the headers, these may come useful:
So then I know that
hostis where API is hosted,originandreferer, they have some difference tho. Your problem may be caused because you try to access them from middleware, try to check them directly from a controller. Also if you need sender hostname in a clear look, you can use this code:If you still get
nullin the response, you can simply debug it, just check for all headers: