Skip Navigation

[Resolved] IP address with registration from

This thread is resolved. Here is a description of the problem and solution.

Problem:
I need to get the IP adrress of the member on my registration from.

Solution:
add the following code in your theme’s functions.php file:

add_shortcode('get_client_ip', 'get_client_ip');
 
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;
}

- Then you can use shortcode in CRED generic hidden field like this:

[cred_generic_field field='client_ip' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[get_client_ip]"
}
[/cred_generic_field]

Relevant Documentation:
For more info:
http://php.net/manual/en/reserved.variables.server.php
https://stackoverflow.com/questions/15699101/get-the-client-ip-address-using-php#answer-15699240

To save the value you need to use cred_save_data hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

0% of people find this useful.

This support ticket is created 7 years 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
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by adriS 7 years ago.

Assisted by: Noman.

Author
Posts
#587528

Tell us what you are trying to do? I'm setting up memership fees for our organisation through a third party company called SAGE. The member need to digitaly sign an agreement, and I need to get the IP adrress of the member on my registration from. Will I be able to do that through Toolset?

Is there any documentation that you are following? can not find "IP address" related documentation

Is there a similar example that we can see?

What is the link to your site? hidden link, but I have not set it up jet. The membership mayment metod on website is still to download a document. I want to do it digitaly

#587541

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Adri,

Thank you for contacting Toolset support. Please add the following code in your theme’s functions.php file:

add_shortcode('get_client_ip', 'get_client_ip');

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;
}

- Then you can use shortcode in CRED generic hidden field like this:

[cred_generic_field field='client_ip' type='hidden' class='' urlparam='']
{
"required":0,
"validate_format":0,
"default":"[get_client_ip]"
}
[/cred_generic_field]

For more info:
hidden link
https://stackoverflow.com/questions/15699101/get-the-client-ip-address-using-php#answer-15699240

To save the value you need to use cred_save_data hook:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

Thank you

#588365

Thank you very much. I will try it today