Title: IP Address Capture
Last modified: August 21, 2016

---

# IP Address Capture

 *  Resolved [whuggett](https://wordpress.org/support/users/whuggett/)
 * (@whuggett)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/ip-address-capture/)
 * Anyone know the best way to capture the IP address into SalesForce, without using
   DaddyAnalytics?
 * I’ve setup forms in the past that do this, but that’s when I can see the specific
   input fields in the code and can figure out where to put the IP lookup script.
   So basically, I’m just looking to figure out where to put the lookup script. 
   I’ve setup a hidden field in my form and a custom field on the SalesForce side.
 * Thanks!
 * [https://wordpress.org/plugins/salesforce-wordpress-to-lead/](https://wordpress.org/plugins/salesforce-wordpress-to-lead/)

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Plugin Author [Nick Ciske](https://wordpress.org/support/users/nickciske/)
 * (@nickciske)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908483)
 * [https://gist.github.com/nciske/3ec33077834b2c04725d](https://gist.github.com/nciske/3ec33077834b2c04725d)
 *  Thread Starter [whuggett](https://wordpress.org/support/users/whuggett/)
 * (@whuggett)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908594)
 * Thanks Nick. I assume this goes in the functions.php of the theme, as per the
   Readme.txt instructions?
 *  Plugin Author [Nick Ciske](https://wordpress.org/support/users/nickciske/)
 * (@nickciske)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908595)
 * Yes.
 * Or, ideally, a functionality plugin 😉
 *  Thread Starter [whuggett](https://wordpress.org/support/users/whuggett/)
 * (@whuggett)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908596)
 * Do I need to identify the form number in the add_filter? I’m using multiple forms,
   and can’t seem to get it to work yet on the main contact form (#1).
 *  Plugin Author [Nick Ciske](https://wordpress.org/support/users/nickciske/)
 * (@nickciske)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908597)
 * Nope. It runs on all fields of all forms by default.
 * Show me your code and link to the form and I can probably spot the error ;-$
 *  Thread Starter [whuggett](https://wordpress.org/support/users/whuggett/)
 * (@whuggett)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908598)
 * Here’s a link to our contact form…
    [Contact Form](http://fracturedvows.com/#homepage-contact)
 * I copied and pasted the code from the sf_w2l_user_ip.php file and changed the
   custom ip field name to “IP_Address__c”, as it is in SalesForce and on our contact
   form’s hidden field.
 * Thanks.
 *  Thread Starter [whuggett](https://wordpress.org/support/users/whuggett/)
 * (@whuggett)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908603)
 * Specifically, this is what I added to the Functions.php file.
 *     ```
       /*----------------------------------------------------------------------*/
       /* Custom function for IP Address Tracking in Contact Form
       /*----------------------------------------------------------------------*/
   
       // Save user ip in a specific field
       // -- replace IP_Address__c with your custom field name
       // -- make a hidden text field in your lead form (make sure it's enabled)
       // -- make sure it can store up to 45 characters (for IPv6 addresses)
   
       add_filter( 'salesforce_w2l_field_value', 'salesforce_w2l_ip_field', 10, 3 );
   
       function salesforce_w2l_ip_field( $val, $field, $form ){
   
       	$my_ip_field = 'IP_Address__c';
   
       	// Target a specific field on all forms
       	if( $field == my_ip_field ){
   
       		if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
       		    $ip = $_SERVER['HTTP_CLIENT_IP'];
       		} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
       		    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
       		} else {
       		    $ip = $_SERVER['REMOTE_ADDR'];
       		}
   
               $val = $ip;
   
       	}
   
           return $val;
   
       }
       ```
   
 *  Plugin Author [Nick Ciske](https://wordpress.org/support/users/nickciske/)
 * (@nickciske)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908686)
 * You did enable your hidden field, right? I don’t see it in the source so it’s
   not being processed by the filter.
 *  [orihmai](https://wordpress.org/support/users/orihmai/)
 * (@orihmai)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908794)
 * Hi Nick!
 * I found a small error on your code. You can notice on **line 14** that _‘my\_ip\
   _field’_ don’t have ‘$’ prefix.
 * `if( $field == my_ip_field ){`
 * This may be obvious to some but others might not notice this easily.
 *  Plugin Author [Nick Ciske](https://wordpress.org/support/users/nickciske/)
 * (@nickciske)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908795)
 * Gist updated. Thanks for catching that!

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘IP Address Capture’ is closed to new replies.

 * ![](https://ps.w.org/salesforce-wordpress-to-lead/assets/icon-256x256.png?rev
   =2316786)
 * [Brilliant Web-to-Lead for Salesforce](https://wordpress.org/plugins/salesforce-wordpress-to-lead/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/salesforce-wordpress-to-lead/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/salesforce-wordpress-to-lead/)
 * [Active Topics](https://wordpress.org/support/plugin/salesforce-wordpress-to-lead/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/salesforce-wordpress-to-lead/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/salesforce-wordpress-to-lead/reviews/)

 * 10 replies
 * 3 participants
 * Last reply from: [Nick Ciske](https://wordpress.org/support/users/nickciske/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/ip-address-capture/#post-4908795)
 * Status: resolved