Home >Backend Development >PHP Tutorial >How to determine access IP in php_PHP tutorial

How to determine access IP in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:49:561144browse

How PHP determines access IP

This article mainly introduces the method PHP determines access IP, involving PHP’s related judgment and usage skills for the server-side predefined variable $_SERVER , friends in need can refer to it

The example in this article describes how PHP determines the access IP. Share it with everyone for your reference. The details are as follows:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

function getIP() {

if (! empty ( $_SERVER ["HTTP_CLIENT_IP"] )) {

$cip = $_SERVER ["HTTP_CLIENT_IP"];

} else if (! empty ( $_SERVER ["HTTP_X_FORWARDED_FOR"] )) {

$cip = $_SERVER ["HTTP_X_FORWARDED_FOR"];

} else if (! empty ( $_SERVER ["REMOTE_ADDR"] )) {

$cip = $_SERVER ["REMOTE_ADDR"];

} else {

$cip = '';

}

preg_match ( "/[d.]{7,15}/", $cip, $cips );

$cip = isset ( $cips [0] ) ? $cips [0] : 'unknown';

unset ( $cips );

return $cip;

}

?>

I hope this article will be helpful to everyone’s PHP programming design.

   Note: For more exciting tutorials, please pay attention to the Bangke Home Web Design Tutorial column,

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1018922.htmlTechArticleHow PHP determines access IP This article mainly introduces the method PHP determines access IP, involving PHP for the server side Friends who need relevant judgment and usage skills of the predefined variable $_SERVER can...
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