Last active
August 29, 2015 14:01
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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