Php function for obtaining the client IP address. Copy the code as follows: functiongetip () {$ IPgetenv (REMOTE_ADDR); $ IP_getenv (HTTP_X_FORWARDED_FOR); if ($ IP _!) ($ Ip _! Unknown) $ IP _; return $ IP;} the following
The code is as follows:
Function getip (){
$ IP = getenv ('remote _ ADDR ');
$ IP _ = getenv ('http _ X_FORWARDED_FOR ');
If ($ IP _! = "") & ($ IP _! = "Unknown") $ IP = $ IP _;
Return $ IP;
}
Which of the following is better?
The code is as follows:
Function getIP ()
{
If (isset ($ _ SERVER )){
If (isset ($ _ SERVER ['http _ X_FORWARDED_FOR ']) {
$ Realip = $ _ SERVER ['http _ X_FORWARDED_FOR '];
} Elseif (isset ($ _ SERVER ['http _ CLIENT_IP ']) {
$ Realip = $ _ SERVER ['http _ CLIENT_IP '];
} Else {
$ Realip = $ _ SERVER ['remote _ ADDR '];
}
} 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 ");
}
}
Return $ realip;
}
The http://www.bkjia.com/PHPjc/321511.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321511.htmlTechArticle code is as follows: function getip () {$ IP = getenv ('remote _ ADDR '); $ IP _ = getenv ('http _ X_FORWARDED_FOR '); if ($ IP _! = "") ($ IP _! = "Unknown") $ IP = $ IP _; return $ IP;} the following...