Obtain the real IP address of the user .? Php *** get the real IP address of the user ** @ returnstring * functionreal_ip () {static $ realipNULL; if ($ realip! NULL) {return $ realip;} if (isset ($ _ SERVER) {if (isset ($ _
/**
* Obtain the real IP address of the user.
*
* @ Return string
*/
Function real_ip (){
Static $ realip = NULL;
If ($ realip! = NULL ){
Return $ realip;
}
If (isset ($ _ SERVER )){
If (isset ($ _ SERVER ['http _ X_FORWARDED_FOR ']) {
$ Arr = explode (',', $ _ SERVER ['http _ X_FORWARDED_FOR ']);
/* Obtain the first non-unknown valid IP string in X-Forwarded-*/
Foreach ($ arr AS $ ip ){
$ Ip = trim ($ ip );
If ($ ip! = 'Unknown '){
$ Realip = $ ip;
Break;
}
}
}
Elseif (isset ($ _ SERVER ['http _ CLIENT_IP ']) {
$ Realip = $ _ SERVER ['http _ CLIENT_IP '];
}
Else {
If (isset ($ _ SERVER ['remote _ ADDR ']) {
$ Realip = $ _ SERVER ['remote _ ADDR '];
}
Else {
$ Realip = '0. 0.0.0 ';
}
}
}
Else {
If (getenv ('http _ X_FORWARDED_FOR ')){
$ Realip = getenv ('http _ X_FORWARDED_FOR ');
}
Elseif (getenv ('http _ CLIENT_IP ')){
$ Realip = getenv ('http _ CLIENT_IP ');
}
Else {
$ Realip = getenv ('remote _ ADDR ');
}
}
Preg_match ("/[\ d \.] {7, 15}/", $ realip, $ onlineip );
$ Realip =! Emptyempty ($ onlineip [0])? $ Onlineip [0]: '0. 0.0.0 ';
Return $ realip;
}
?>
From chaojie2009
Http://www.bkjia.com/PHPjc/478363.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478363.htmlTechArticle? Php/*** get the real IP address of the user ** @ return string */function real_ip () {static $ realip = NULL; if ($ realip! = NULL) {return $ realip;} if (isset ($ _ SERVER) {if (isset ($ _...