首頁 >後端開發 >php教程 >判斷存取IP

判斷存取IP

WBOY
WBOY原創
2016-07-25 09:11:35913瀏覽
判断访问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. ?>
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn