Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

How can I get IP ?

Questions related to using nuBuilder Forte.
miasoft
Posts: 156
Joined: Wed Dec 23, 2020 12:28 pm
Location: Russia, Volgograd
Has thanked: 32 times
Been thanked: 7 times
Contact:

How can I get IP ?

Unread post by miasoft »

I'd like to get client's IP. How can I do it?
Wbr, miasoft.
kev1n
nuBuilder Team
Posts: 4288
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 442 times
Contact:

Re: How can I get IP ?

Unread post by kev1n »

In 4.5., there's a nuGetIPAddress() PHP function.
miasoft
Posts: 156
Joined: Wed Dec 23, 2020 12:28 pm
Location: Russia, Volgograd
Has thanked: 32 times
Been thanked: 7 times
Contact:

Re: How can I get IP ?

Unread post by miasoft »

I tried:

Code: Select all

// form CustomCode
function nuBeforeSave() {
   if (nuFORM.edited === true) {
      var ip=nuGetIPAddress(); // error below
      //var   ip='123456';  //--- is OK
      $('#gam_ip').val(ip).change();
        return true;
    }
}
I get this error:
Uncaught ReferenceError: nuGetIPAddress is not defined
at nuBeforeSave (<anonymous>:18:14)
at nuUpdateData (nuajax.js?ts=20210219130849:664)
at nuSaveAction (nuform.js?ts=20210219130849:3332)
at HTMLInputElement.onclick ((index):1)
My version.txt file:
nuBuilder Forte 4.5
DB Version: V.4.5-2021.01.28.00
Files Version: V.4.5-2021.01.29.01
(V.MajorVersion-CurrentDate.BuildNumber)
Haw can I test real version? May be update is wrong?
Wbr, miasoft.
kev1n
nuBuilder Team
Posts: 4288
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 442 times
Contact:

Re: How can I get IP ?

Unread post by kev1n »

This is a PHP function, not JavaScript. Add your check in the BS event.
miasoft
Posts: 156
Joined: Wed Dec 23, 2020 12:28 pm
Location: Russia, Volgograd
Has thanked: 32 times
Been thanked: 7 times
Contact:

Re: How can I get IP ?

Unread post by miasoft »

kev1n wrote:This is a PHP function, not JavaScript. Add your check in the BS event.
1. I added code in BS and now get IP. How can I return(or save) this IP-value in my EditForm?

Code: Select all

        $ip=nuGetIPAddress();
       nuDebug();
        nuSetFormValue('gam_ip', $ip);  //don't work
2. I created Button "GetIp" on EditForm and procedure "get_ip". Onclick-event run "nuRunPHPHidden('get_ip', 0)"

Code: Select all

 
//my  get_ip proc
     $ip=nuGetIPAddress();
      nuDebug($ip);
      $v=" '$ip' ";
      $j = " $('#gam_ip').val($v).change(); ";
      nuDebug($j);
      nuJavascriptCallback($j);   // all work
But I'd like to get IP automatically.
Wbr, miasoft.
kev1n
nuBuilder Team
Posts: 4288
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 442 times
Contact:

Re: How can I get IP ?

Unread post by kev1n »

In BS (latest 4.5. version), you can add this line:

Code: Select all

nuSetNuDataValue($nudata, '', 'gam_ip', nuGetIPAddress());
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: How can I get IP ?

Unread post by icoso »

Cant you use the PHP function to grab ANY user environment variable?
Such as:

$IpAddress = getenv('REMOTE_ADDR')

Then assign it to your field via:

nuSetNuDataValue($nudata, '', 'cust_IPAddress', $IPAddress);

Could this be used in the Before Save BS or the Before Edit? If used in Before Edit would the form screen display the IP address?
Last edited by icoso on Fri Feb 19, 2021 4:18 pm, edited 1 time in total.
miasoft
Posts: 156
Joined: Wed Dec 23, 2020 12:28 pm
Location: Russia, Volgograd
Has thanked: 32 times
Been thanked: 7 times
Contact:

Re: How can I get IP ?

Unread post by miasoft »

kev1n wrote:In BS (latest 4.5. version), you can add this line:

Code: Select all

nuSetNuDataValue($nudata, '', 'gam_ip', nuGetIPAddress());
I get error:
19.02_1.png
I search "nuSetNuDataValue" in core-files and SQL-dump - no result
You do not have the required permissions to view the files attached to this post.
Wbr, miasoft.
icoso
Posts: 181
Joined: Sun Feb 07, 2021 11:09 pm
Been thanked: 1 time

Re: How can I get IP ?

Unread post by icoso »

You need the latest nudata.php file. I think you can download this from their github site

Look at this post.
https://forums.nubuilder.cloud/viewtopic.php?f=20&t=10823


Kev1n discussed this new function. There are two of them in this new nudata.php file.

function nuGetNuDataValue($nudata, $formId, $field)
function nuSetNuDataValue(&$nudata, $formId, $field, $value)

These allow you to get data from a field and then replace it with something else before it's saved in the BS event code. I would assume this would work in the BE too.

NOTE: Save your original nudata.php file BEFORE overwriting it in case it breaks something else. ie: change current one to nudata-orig1.php before you replace it with the new nudata.php.
Post Reply