PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Client IP Behind Proxy

  1. KieranW
    Member

    I want to purchase Gravity Forms, it looks like an amazing plugin, but I'm wondering if it can accurately detect the correct client IP address. My webserver is behind a load balancer, so the regular client IP will be that of the load balancer. The load balancer does add the standard "forwarded-for" HTTP header with the clients IP address, so it's very simple to get this information. Does Gravity Forms fetch the right client IP address automatically, or is this not supported? It's very important for my usage of Gravity Forms, or any other form plugin, that it can correctly log the true client IP address.

    Posted 12 years ago on Saturday August 25, 2012 | Permalink
  2. You have access to all the HTTP headers in the request. It's not stored automatically, but you can grab it and store it if you need to. Here is how you can grab it:

    [php]
    $headers = apache_request_headers();
    $real_client_ip = $headers["X-Forwarded-For"];

    You could add a hidden field in your form to store the IP address. Check the box to "Allow field to be populated dynamically." Then grab the value and store it in that field using the gform_field_value_$parameter_name filter. If you gave the field a parameter name of "real_client_ip" your filter would be called gform_field_value_real_client_ip.

    http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name

    More about populating a field dynamically:
    http://www.gravityhelp.com/documentation/page/Allow_field_to_be_populated_dynamically

    After you make your purchase, let us know if you need more help with implementation.

    Posted 12 years ago on Saturday August 25, 2012 | Permalink