Skip Navigation

[Resolved] Storing IP address

This support ticket is created 3 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by matthewL-7 3 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1860089

Hi

I am trying to store the IP address of a user when they register, I followed this article here:
https://toolset.com/forums/topic/ip-address-with-registration-from/

But it didn't work any ideas why this no longer works?

Thanks

#1860681

Hi, that ticket includes information about getting the IP using a custom shortcode and placing it in a generic hidden field in the Form. However, it does not include a code sample showing how to save that generic field into some custom field in the database using the cred_save_data hook. If the problem is the IP is not included as the value the hidden field (you would be able to tell by inspecting the generic hidden field value in the browser elements console when you load the page containing the Form), that indicates a problem in the shortcode that determines the IP. If the problem is the IP is included in the generic field value, but not stored in the database, that indicates a problem in the cred_save_data hook.

Can you tell me if the problem is the IP is not visible in the generic field's value attribute, or is the problem that the IP is visible in the generic field but not stored in the database anywhere? If it's the latter, please include your cred_save_data code here for me to review.

#1861689

Oh right I see, I was just trying to use a Toolset custom field to save it straight to this.

function get_client_ip() {
    $ipaddress = '';
    if (isset($_SERVER['HTTP_CLIENT_IP']))
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_X_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if(isset($_SERVER['HTTP_FORWARDED']))
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if(isset($_SERVER['REMOTE_ADDR']))
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}

I setup this for a shortcode and enabled in Front end settings.

Based on what you said I thought ah OK I need to insert the custom field instead of using a generic field. So I placed the following instead:
[cred_field field='ip-address' force_type='field' class='form-control' output='bootstrap' value='[get_client_ip]']

However this still didn't work?

Thanks.

#1861701

What do you see if you place the shortcode outside of the field, for testing purposes? Also, it's always a good idea to close a custom shortcode explicitly, like so:

Client IP shortcode: [get_client_ip][/get_client_ip]<br />
[cred_field field='ip-address' force_type='field' class='form-control' output='bootstrap' value='[get_client_ip][/get_client_ip]']

Is the IP written out before the field correctly on the front-end of the site? If not, check your shortcode PHP. The snippet you shared (https://toolset.com/forums/topic/storing-ip-address/#post-1861689) includes the shortcode function, but not the line that actually initializes the shortcode using add_shortcode. There should be something like this in your code:

add_shortcode( 'get_client_ip', 'get_client_ip' );
#1867719

Thanks a lot, sorted! 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.