APIs & Integrations

ctoh
HubSpot Employee
HubSpot Employee

IP addresses retrieved through Forms API

I have set up an external form using the HubSpot Forms API. The IP addresses being recorded for the contacts seems to be pretty similar (10.0.0.xxx), so it might be that there’s something wrong when retrieving it from the server request. While the form is capturing the submissions fine, I am wondering if the script is pulling in some static IP and changing the last few digits.

Here’s the code:

global $base_url;
    $fname = $form_state->getValue('fname');
    $lname = $form_state->getValue('lname');
    $email = $form_state->getValue('email');
    $phone = $form_state->getValue('phone');
    $company = $form_state->getValue('company');
    $requirement = $form_state->getValue('requirement');

    $hubspotutk = $_COOKIE['hubspotutk'];
    $ip_addr = $_SERVER['REMOTE_ADDR'];
    $jobtype = 'Media';
    $pageTitle = 'Contact us';
    $uri = $_SERVER['REQUEST_URI'];
    $hubspot_context = array(
      'hutk' => $hubspotutk,
      'ipAddress' => $_SERVER['REMOTE_ADDR'],
      'pageUrl' => $base_url . $uri,
      'pageName' => $pageTitle
    );
    $hubspot_string = json_encode($hubspot_context);

    $str_post = "first_name=" . urlencode($fname)
        . "&last_name=" . urlencode($lname)
        . "&message=" . urlencode($requirement)
        . "&email=" . urlencode($email)
        . "&phone=" . urlencode($phone)
        . "&jobtype=" . urlencode($jobtype)
        . "&company=" . urlencode($company)
        . "&hs_context=" . urlencode($hubspot_string);

    $endpoint = 'http://forms.hubspot.com/uploads/form/v2/481864/056229e6-d64e-41ff-9483-3f991d84df2d';

    $ch = @curl_init();

    @curl_setopt($ch, CURLOPT_POST, TRUE);
    @curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
    @curl_setopt($ch, CURLOPT_URL, $endpoint);
    @curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
    @curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    $response = @curl_exec($ch);
    // Log the response from HubSpot as needed.
    $status_code = @curl_getinfo($ch, CURLINFO_HTTP_CODE);
    // Log the response status code.
    @curl_close($ch);

Appreciate any insight into this. Thanks!

3 Replies 3
Dadams
HubSpot Employee
HubSpot Employee

IP addresses retrieved through Forms API

Hi @Christopher_Toh

Are you testing this on a computer on your local network? 10.x.x.x address are reserved for local networks, so if the system processing the form submissions is on the same network that you’re testing the form from, it could be picking up the local IP you’re testing from.

0 Upvotes
Ankit_Gupta
Member

IP addresses retrieved through Forms API

Hi,

The IP address being used on the forms is 52.206.x.x

0 Upvotes
Dadams
HubSpot Employee
HubSpot Employee

IP addresses retrieved through Forms API

Hi @Ankit_Gupta

The actual IP provided by $_SERVER['REMOTE_ADDR'] can vary depending on the setup of your network. If your server is behind a load balancer or proxy system you may end up getting the IP of those machines instead of the visitor who filled out the form.

How you get the IP is going to depend heavily on your network configuration, but there are some other details and some suggested solutions here:

Determine IP Address of Client Behind Amazon ELB

amazon-web-services, locale, load-balancing

0 Upvotes