title: Grabing ip address in aspx page for a php website
body: <p>I am trying to grab clients IP address who is  requesting my website using the following code:</p>
  
  <pre><code> protected string GetIPAddress()
          {
              System.Web.HttpContext context = System.Web.HttpContext.Current;
              string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  
              if (!string.IsNullOrEmpty(ipAddress))
              {
                  string[] addresses = ipAddress.Split(',');
                  if (addresses.Length != 0)
                  {
                      return addresses[0];
                  }
              }
  
              return context.Request.ServerVariables["REMOTE_ADDR"];
          }
  </code></pre>
  
  <p>I have this in my c# web service code which resides on the same server where my client side web server code resides  (in this case it is php).</p>
  
  <p>So client makes a requuest to my php website which resides on server 1 .the php wesbite make a request to c# webservice for data which resides on server 1 .The ip address captured in my case is always where my php code resides .Is it because in my case its the php code on the server 1 making request .</p>
  
  <p>Should i be grabbing the ip address in my php code and pass it to my c# web service to log into database .
  Any suggestion would be greatly appreciated
  Thanks,
  Anurag</p>