Skip to content

Instantly share code, notes, and snippets.

@nciske
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nciske/3ec33077834b2c04725d to your computer and use it in GitHub Desktop.
Save nciske/3ec33077834b2c04725d to your computer and use it in GitHub Desktop.
Save user ip in a specific field -- replace user_ip__c with your custom field name - make sure it can store up to 45 characters (for IPv6 addresses)
<?php
// Save user ip in a specific field
// -- replace user_ip__c with your custom field name
// -- make that 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 = 'user_ip__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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment