Page 1 of 2

How can I get IP ?

Posted: Fri Feb 19, 2021 10:09 am
by miasoft
I'd like to get client's IP. How can I do it?

Re: How can I get IP ?

Posted: Fri Feb 19, 2021 10:23 am
by kev1n
In 4.5., there's a nuGetIPAddress() PHP function.

Re: How can I get IP ?

Posted: Fri Feb 19, 2021 1:24 pm
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?

Re: How can I get IP ?

Posted: Fri Feb 19, 2021 1:27 pm
by kev1n
This is a PHP function, not JavaScript. Add your check in the BS event.

Re: How can I get IP ?

Posted: Fri Feb 19, 2021 3:34 pm
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.

Re: How can I get IP ?

Posted: Fri Feb 19, 2021 3:51 pm
by kev1n
In BS (latest 4.5. version), you can add this line:

Code: Select all

nuSetNuDataValue($nudata, '', 'gam_ip', nuGetIPAddress());

Re: How can I get IP ?

Posted: Fri Feb 19, 2021 4:14 pm
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?

Re: How can I get IP ?

Posted: Fri Feb 19, 2021 4:18 pm
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

Re: How can I get IP ?

Posted: Fri Feb 19, 2021 4:25 pm
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.

Re: How can I get IP ?

Posted: Fri Feb 19, 2021 4:43 pm
by kev1n