问题描述
有很多关于如何使用javascript获取http标头的问题,但是由于某些原因,它们不会显示HTTP_CF_IPCOUNTRY标头。
There are many SO questions how to get http headers with javascript, but for some reason they don't show up HTTP_CF_IPCOUNTRY header.
如果我尝试使用php echo $ _SERVER [ HTTP_CF_IPCOUNTRY];
,它可以正常工作,所以CF可以正常工作。
If I try to do with php echo $_SERVER["HTTP_CF_IPCOUNTRY"];
, it works, so CF is working just fine.
是
推荐答案
假设您正在谈论客户端JavaScript:不,不可能
Assuming you are talking about client side JavaScript: no, it isn't possible.
- 浏览器向服务器发出HTTP请求。
- 服务器会注意到IP地址请求来自
- 服务器在数据库中查找该IP地址并找到匹配的国家/地区
- 服务器将该国家/地区传递给PHP li>
- The browser makes an HTTP request to the server.
- The server notices what IP address the request came from
- The server looks up that IP address in a database and finds the matching country
- The server passes that country to PHP
数据永远不会靠近浏览器。
The data never even goes near the browser.
供JavaScript访问,则需要将其与服务器端代码一起阅读,然后将其作为响应返回给浏览器。
For JavaScript to access it, you would need to read it with server side code and then put it in a response back to the browser.
这篇关于使用JavaScript获取Cloudflare的HTTP_CF_IPCOUNTRY标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!