deevo's avatar
Level 5

Trying to get the hostname of the url making API request to laravel website...

So, I am building a little API for a licensing system for updates on premium wordpress themes. Everything is going great except I am trying to check what is the hostname (somedomain.com) making the request the API endpoint. The request is coming from a WordPress theme to the Laravel license manager for downloading the updates to the themes.

I tried to use the

$request->headers('host'); 

But with no luck. This will return the host if the API call originates from a Laravel site. Anyway, I am just looking for a way to capture that hostname when they hit an API end point on a laravel API.

0 likes
7 replies
jlrdw's avatar

Have you tryed $_SERVER['REMOTE_HOST']

deevo's avatar
Level 5

No dice. Undefined index on $_SERVER['REMOTE_HOST']

Basically, I am listening in the API endpoint laravel controller and just trying to catch the hostname that sent the request to compare it against a license key that is stored in the DB to see if that hostname is authorized to download the update.

jlrdw's avatar

Have you looked through php manual on various $_SERVER functions, another is $_SERVER['REMOTE_ADDR'], worth a try.

deevo's avatar
Level 5

Yeah I went through them all. I even thought maybe when I was returning data from the request that something was going wrong. So, I just logged the incoming request so I could see it, but still not working. It is giving local server data and nothing from the requesting service.

Snapey's avatar
Snapey
Best Answer
Level 122

You will possibly need to get the hostname from the request at the wordpress end and then send it in the API. You can then return a licence token that is bound to that host only.

Snapey's avatar

These are the relevant bits from the docs

'REMOTE_ADDR' The IP address from which the user is viewing the current page.

'REMOTE_HOST' The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user. Note: Your web server must be configured to create this variable. For example in Apache you'll need HostnameLookups On inside httpd.conf for it to exist. See also gethostbyaddr().

But this will not work in most shared hosting environments where hundreds of domain names can have the same IP address

Please or to participate in this conversation.