Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to prohibit domestic ip from visiting websites by php

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how php forbids domestic ip to visit the website". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how php prohibits domestic ip from visiting the website".

Php forbids domestic ip to visit the website: 1, to obtain the ip address through "$_ SERVER ['REMOTE_ADDR']"; 2, to judge and prohibit domestic ip from visiting the website through "if ((! empty ($banned [' data'] ['country_id']) {...}".

This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer

How does php prohibit domestic ip from visiting the website?

Restrict domestic IP access to our website with php code

Principle:

Use the IP interface of Taobao to determine whether IP is a domestic ip, and access is not allowed if it is domestic (CN).

The code is as follows:

$ip = $_ SERVER ['REMOTE_ADDR']; $content = file_get_contents (' http://ip.taobao.com/service/getIpInfo.php?ip='.$ip);$banned = json_decode (trim ($content), true); $lan = strtolower ($_ SERVER ['HTTP_ACCEPT_LANGUAGE']) If ((! empty ($banned ['data'] [' country_id']) & & $banned ['data'] [' country_id'] = = 'CN') | | strstr ($lan,' zh') {header ("HTTP/1.0 404 Not Found"); echo 'HTTP/1.0 404 Not Found';exit Thank you for your reading. The above is the content of "how php prohibits domestic ip from visiting websites". After the study of this article, I believe you have a deeper understanding of how php prohibits domestic ip from visiting websites, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report