I want to create an API, and to authenticate API consumers, I will provide an API KEY, App-id and App-Secret. The problem is that I want to know where the http Request is coming from, so that I can know if the Host that is making que request is the registered Host. For example : www.someone.com has an app-id :0001, app-secret:1200 and api-key:458. If this credentials are used to make A request, I want to know if the requester is really www.someone.com
5条回答 默认 最新
- doulu4316 2016-03-26 03:50关注
Use
$_SERVER['HTTP_REFERER']
. It is the address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modifyHTTP_REFERER
as a feature.For further restrictions you can perform the following.
example.com
should be changed to your domain.IIS set below in web config:
add name="Access-Control-Allow-Origin" value="http://www.example.com"
Apache set below in httpd.conf/apache.conf
Header add Access-Control-Allow-Origin "http://www.example.com"
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报