Here is code to get the IP Address For User Tracking

digitalpower

BANNED
Joined
Dec 16, 2008
Messages
303
Reaction score
70
In case you want to do some simple user tracking on your ASP.NET website, you can use this function to get the current user's IP address.

Code:
Public Shared Function GetIPAddress() As String
        Dim sIPAddress As String
        sIPAddress = HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR")
        If sIPAddress = "" Then
            sIPAddress = HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
        End If
        Return sIPAddress
    End Function
 
Public Shared Function GimmeClientIP() as String
Return Request.UserHostAddress
End Function



Note: The Request.UserHostAddress return's the Client's IP. Works all the time for me :) :) :)
 
Note: The Request.UserHostAddress return's the Client's IP. Works all the time for me

The code by digitialpower gets the users real IP even if they are behind a proxy, your's will just get the proxy address:)

Nice going dp :)
 
Can I use it with my wordpress blog? or is there any solution for wordpress (php/html)?
 
here you have a php code for it.

PHP:
if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '')
		{ 
 	   $sIP = $_SERVER['HTTP_X_FORWARDED_FOR']; 
 	   $sProxy = $_SERVER['REMOTE_ADDR']; 
 	   $sHost = @gethostbyaddr($_SERVER['HTTP_X_FORWARDED_FOR']); 
		}
		elseif ( isset( $_SERVER['REMOTE_ADDR'] ) )
		{ 
 	   $sIP = $_SERVER['REMOTE_ADDR']; 
 	   $sHost = @gethostbyaddr($_SERVER['REMOTE_ADDR']); 
		}
 
Back
Top