Home >Backend Development >PHP Tutorial >Determine access IP

Determine access IP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:11:35954browse
判断访问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. ?>
复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn