JeremyS JeremyS - 7 months ago 66
PHP Question

How do I catch the request url / domain in my REST api?

This may have a simple answer (and I hope it does) but looking online I only found examples of how to get the current URL/Domain. No where could I find how to get that of the incoming http requst.

My set up is a REST api that handles the typical GET/POST/DELETE/PUT requests. I have to return domain information for clients about the domain they're pulling from. Hence, if a client using my CMS clicks on info, he must receive info about the domain he is logged into (and thus sending the request from).

I chose not to add code here, seeing as my question pertains less to actual code as it does to methodology. Thanks in advance for any and all answers!

Answer Source

In Internet every address could be faked (VPN, proxies etc). It's one of fundamental principles of the network.

You will never could detect with 100% warranty, so the maximum what You could have is $_SERVER['HTTP_REFERER'] and $_SERVER['REMOTE_ADDR'].

You could make additional verification for it's existence before to save/process it, but it could cost some additional performance of Your server.

If Your aim is to provide some additional access rules to some methods / data, You should use an other verification mechanism (tokens, passwords etc).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download