This article introduces two functions: one is to verify the IP address, and the other is to obtain the real IP address of the user. it is also a common operation function of two IP addresses. if you need it, you can refer to it. The code for obtaining the real IP address of a user is as follows...
This article introduces two functions: one is to verify the IP address, and the other is to obtain the real IP address of the user. it is also a common operation function of two IP addresses. if you need it, you can refer to it.
Obtain the real IP address of a user
The code is as follows: |
|
Function get_client_ip () { If (getenv ("REMOTE_ADDR") & strcasecmp (getenv ("REMOTE_ADDR"), "unknown ")) { $ Onlineip = getenv ("REMOTE_ADDR "); Return $ onlineip; } If (isset ($ _ SERVER ['remote _ ADDR ']) & $ _ SERVER ['remote _ ADDR '] & strcasecmp ($ _ SERVER ['remote _ ADDR'], "unknown ")) { $ Onlineip = $ _ SERVER ['remote _ ADDR ']; Return $ onlineip; } If (getenv ("HTTP_CLIENT_IP") & strcasecmp (getenv ("HTTP_CLIENT_IP"), "unknown ")) { $ Onlineip = getenv ("HTTP_CLIENT_IP "); Return $ onlineip; } If (getenv ("HTTP_X_FORWARDED_FOR") & strcasecmp (getenv ("HTTP_X_FORWARDED_FOR"), "unknown ")) { $ Onlineip = getenv ("HTTP_X_FORWARDED_FOR "); } Return $ onlineip; } |
Determines whether it is an IP address.
The code is as follows: |
|
Function is_ip ($ IP) { $ IP_ARRAY = explode (".", $ IP ); $ IP_ARRAY_NUM = sizeof ($ IP_ARRAY ); If ($ IP_ARRAY_NUM! = 4) { Return FALSE; } $ I = 0; For (; $ I <$ IP_ARRAY_NUM; ++ $ I) { If (! Is_numeric ($ IP_ARRAY [$ I]) & $ IP_ARRAY [$ I] <0 | 255 <$ IP_ARRAY [$ I]) { Return FALSE; } If (! ($ I = 3 )&&! ($ IP_ARRAY [$ I] = 255 )) { Continue; } Return FALSE; } Return TRUE; }
|
Permanent link:
Reprint at will! Include the article address.