1

I'm building an API in PHP. I want the user to only be able to use the public and private keys per domain, (as eventualy I would like to try to be able to charge for large requests). Is there any way to tell if the request is being sent from the correct domain?

regards

4
  • 2
    @Wesley van Opdorp meta.stackexchange.com/questions/103777/… Commented Aug 31, 2011 at 14:08
  • You can look at the source IP of the requests, but given how easy it is to set up a proxy servers, nat gateways, etc... an IP appearing to be from the correct place means essentially nothing. Commented Aug 31, 2011 at 14:09
  • @ Layke - thank you, that is correct, I accept answers when I feel I have been answered (correctly that is)! Commented Aug 31, 2011 at 14:21
  • Are we saying that it is not possible then? Commented Aug 31, 2011 at 14:22

1 Answer 1

1

Check out the global $_SERVER variable

http://php.net/manual/en/reserved.variables.server.php

You can get the domain name the request is sent from with

$_SERVER['REMOTE_HOST']
Sign up to request clarification or add additional context in comments.

4 Comments

That is incorrect. Straight from the docs, $_SERVER['SERVER_NAME'] contains "The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host."
Can this be altered and changed?
Might want to take a look at this yiiframework.com/forum/index.php?/topic/…
The Host-header mentioned in the linked forum post, is bullshit. Not in the sense that it doesn't exist, but that it would have anything to do with the contents of $_SERVER['REMOTE_HOST']. It's sole purpose is to identify which host should receive the request, being useful for virtualhost setup. The contents of the sent header, if present, are found in $_SERVER['HTTP_HOST']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.