duanoucuo7045 2014-08-26 22:11
浏览 142
已采纳

如何在php中获取http请求源

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 modify HTTP_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"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)
编辑
预览

报告相同问题?