欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 判断访问IP

程序员文章站 2022-04-07 09:03:18
...

判断访问IP

php代码

  1. function getIP() {
  2. if (! empty ( $_SERVER ["HTTP_CLIENT_IP"] )) {
  3. $cip = $_SERVER ["HTTP_CLIENT_IP"];
  4. } else if (! empty ( $_SERVER ["HTTP_X_FORWARDED_FOR"] )) {
  5. $cip = $_SERVER ["HTTP_X_FORWARDED_FOR"];
  6. } else if (! empty ( $_SERVER ["REMOTE_ADDR"] )) {
  7. $cip = $_SERVER ["REMOTE_ADDR"];
  8. } else {
  9. $cip = '';
  10. }
  11. preg_match ( "/[\d\.]{7,15}/", $cip, $cips );
  12. $cip = isset ( $cips [0] ) ? $cips [0] : 'unknown';
  13. unset ( $cips );
  14. return $cip;
  15. }
  16. ?>
复制代码
php
相关标签: php 判断访问IP