Get Cloudflare's HTTP_CF_IPCOUNTRY header with javascript?

后端 未结 4 1078
再見小時候
再見小時候 2021-02-08 11:08

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.

If I try to do with php echo

4条回答
  •  滥情空心
    2021-02-08 11:47

    Assuming you are talking about client side JavaScript: no, it isn't possible.

    1. The browser makes an HTTP request to the server.
    2. The server notices what IP address the request came from
    3. The server looks up that IP address in a database and finds the matching country
    4. The server passes that country to PHP

    The data never even goes near the browser.

    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.

提交回复
热议问题