如何使用 PHP 检测代理

有时人们使用代理来掩盖他们的真实 IP 地址。我不要这个。我想限制该用户访问我的网站。

我用 PHP 建立了一个网站。


汪汪一只猫
浏览 168回答 3
3回答

噜噜哒

您可以使用“ HTTP HEADERS ”阻止代理   function shapeSpace_block_proxy_visits() {     $headers = array('CLIENT_IP','FORWARDED','FORWARDED_FOR','FORWARDED_FOR_IP','VIA','X_FORWARDED','X_FORWARDED_FOR','HTTP_CLIENT_IP','HTTP_FORWARDED','HTTP_FORWARDED_FOR','HTTP_FORWARDED_FOR_IP','HTTP_PROXY_CONNECTION','HTTP_VIA','HTTP_X_FORWARDED','HTTP_X_FORWARDED_FOR');      foreach ($headers as $header){         if (isset($_SERVER[$header])) {             die('Proxy access not allowed.');         }      }   }

POPMUISE

2 方法可以实现它。这些技术适用于任何支持 PHP 的站点,包括 WordPress、Drupal、Joomla 等1)通过端口扫描阻止代理访问function blockproxyvisits() {$ports = array(80,81,553,554,1080,3128,4480,6588,8000,8080);foreach ($ports as $port) {    if (@fsockopen($_SERVER['REMOTE_ADDR'], $port, $errno, $errstr, 5)) {        die('Proxy access not allowed.');    }} }2) 通过 HTTP 标头阻止代理访问function blockproxy_visits() {$headers = array('CLIENT_IP','FORWARDED','FORWARDED_FOR','FORWARDED_FOR_IP','VIA','X_FORWARDED','X_FORWARDED_FOR','HTTP_CLIENT_IP','HTTP_FORWARDED','HTTP_FORWARDED_FOR','HTTP_FORWARDED_FOR_IP','HTTP_PROXY_CONNECTION','HTTP_VIA','HTTP_X_FORWARDED','HTTP_X_FORWARDED_FOR');foreach ($headers as $header){    if (isset($_SERVER[$header])) {        die('Proxy access not allowed.');    }} }这里的缺点是扫描开放端口比简单地检查 HTTP 标头需要更多的时间
打开App,查看更多内容
随时随地看视频慕课网APP