How can I get IP ?

Questions related to using nuBuilder Forte.

How can I get IP ?

Unread postby miasoft » Fri Feb 19, 2021 6:39 pm

I'd like to get client's IP. How can I do it?
Wbr, miasoft.
miasoft
 
Posts: 100
Joined: Wed Dec 23, 2020 8:58 pm
nuBuilder Version: 4.5

Re: How can I get IP ?

Unread postby kev1n » Fri Feb 19, 2021 6:53 pm

In 4.5., there's a nuGetIPAddress() PHP function.
kev1n
nuBuilder Team
 
Posts: 2048
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: How can I get IP ?

Unread postby miasoft » Fri Feb 19, 2021 9:54 pm

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.
miasoft
 
Posts: 100
Joined: Wed Dec 23, 2020 8:58 pm
nuBuilder Version: 4.5

Re: How can I get IP ?

Unread postby kev1n » Fri Feb 19, 2021 9:57 pm

This is a PHP function, not JavaScript. Add your check in the BS event.
kev1n
nuBuilder Team
 
Posts: 2048
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: How can I get IP ?

Unread postby miasoft » Sat Feb 20, 2021 12:04 am

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.
miasoft
 
Posts: 100
Joined: Wed Dec 23, 2020 8:58 pm
nuBuilder Version: 4.5

Re: How can I get IP ?

Unread postby kev1n » Sat Feb 20, 2021 12:21 am

In BS (latest 4.5. version), you can add this line:
Code: Select all
nuSetNuDataValue($nudata, '', 'gam_ip', nuGetIPAddress());
kev1n
nuBuilder Team
 
Posts: 2048
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: How can I get IP ?

Unread postby icoso » Sat Feb 20, 2021 12:44 am

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 Sat Feb 20, 2021 12:48 am, edited 1 time in total.
icoso
 
Posts: 181
Joined: Mon Feb 08, 2021 7:39 am
nuBuilder Version: 4.5

Re: How can I get IP ?

Unread postby miasoft » Sat Feb 20, 2021 12:48 am

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
19.02_1.png (15.06 KiB) Viewed 931 times

I search "nuSetNuDataValue" in core-files and SQL-dump - no result
Wbr, miasoft.
miasoft
 
Posts: 100
Joined: Wed Dec 23, 2020 8:58 pm
nuBuilder Version: 4.5

Re: How can I get IP ?

Unread postby icoso » Sat Feb 20, 2021 12:55 am

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

Look at this post.
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.
icoso
 
Posts: 181
Joined: Mon Feb 08, 2021 7:39 am
nuBuilder Version: 4.5

Re: How can I get IP ?

Unread postby kev1n » Sat Feb 20, 2021 1:13 am

kev1n
nuBuilder Team
 
Posts: 2048
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Next

Return to General

Who is online

Users browsing this forum: No registered users and 13 guests

cron