如何在php中获取http请求源 [英] How to get http request origin in php

查看:29
本文介绍了如何在php中获取http请求源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 API,并验证 API 消费者,我将提供 API KEY、App-id 和 App-Secret.问题是我想知道http请求来自哪里,这样我就可以知道发出que请求的主机是否是注册的主机.例如:www.someone.com 有一个 app-id:0001、app-secret:1200 和 api-key:458.如果这个凭证是用来做A请求的,我想知道这个请求者是不是真的www.someone.com

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

推荐答案

使用 $_SERVER['HTTP_REFERER'].它是将用户代理引用到当前页面的页面地址(如果有的话).这是由用户代理设置的.并非所有用户代理都会设置此项,有些提供修改 HTTP_REFERER 作为功能的能力.

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.

有关进一步的限制,您可以执行以下操作.example.com 应更改为您的域.

For further restrictions you can perform the following. example.com should be changed to your domain.

IIS 在 web 配置中设置如下:

add name="Access-Control-Allow-Origin" value="http://www.example.com"

Apache 设置在 httpd.conf/apache.conf

Header add Access-Control-Allow-Origin "http://www.example.com"

这篇关于如何在php中获取http请求源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆