Home > Software engineering >  How does laravel know the value of request()->getHttpHost()
How does laravel know the value of request()->getHttpHost()

Time:11-05

If I SSH into a server running a laravel app and run in the tinker command line:

print_r(request()->getHttpHost());

This tells me the domain name of the server. But how does it know? Where is this information stored. What does it query to get this information. And why doesn't it return "localhost" or something similar.

CodePudding user response:

Laravel will first look at the X_FORWARDED_HOST HTTP header. If this header is not available, it will look at the HOST HTTP header.

If neither of those headers are available (i.e. when using the command-line) it will look at the SERVER_NAME configuration variable. Finally, if the server name is also not available it will return the value of the SERVER_ADDR configuration variable.

You can read the source of Request::getHttpHost here.

  • Related