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

判断访问IP

程序员文章站 2023-12-23 09:10:34
...
判断访问IP
  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. ?>
复制代码
相关标签: 判断访问IP

上一篇:

下一篇: