当前位置:Gxlcms > PHP教程 > 判断访问IP

判断访问IP

时间:2021-07-01 10:21:17 帮助过:16人阅读

判断访问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. ?>

人气教程排行