• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

User's IP/Location

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • User's IP/Location

    We have an internal app that is used at different locations. I would like to know the location of the user. Is there a way to retrieve the IP address of the user within the Valence back-end application?

  • #2
    The IP address is stamped on the session record for the user (file VVSESSDATA), so you should be able to get at it via the session ID. Something like this in your RPG should work:
    Code:
    // pull in session ID, which is passed automatically on each Ajax call ("sid" is a 64 char alpha field)
    sid = vvIn_char('sid'); 
    
    // retreive IP address from session record ("ipAddress" is a 20 char alpha field)
    exec sql select vvClientIp into :ipAddress 
               from vvsessdata
              where vvsessid=:sid;
    Or you could use vvUtility_getSessVar() and look at the returned data structure, which is modeled after the VVSESSDATA file object.
    Last edited by robert.swanson; 08-22-2016, 04:46 PM.

    Comment


    • #3
      Alternative method: use vvUtility_getSessVar. Documentation is at http://service.cnxcorp.com/valence-5...lkit.vvUtility. Look at the example RPG code in the doc for getSessVar. You want to set up something similar. The value in the session structure you're looking for is vvClientIP.

      Comment


      • #4
        That works fantastic... Thank you both!

        Comment


        • #5
          Originally posted by richard.milone View Post
          Alternative method: use vvUtility_getSessVar. Documentation is at http://service.cnxcorp.com/valence-5...lkit.vvUtility. Look at the example RPG code in the doc for getSessVar. You want to set up something similar. The value in the session structure you're looking for is vvClientIP.
          This no longer works. How do I retrieve the IP address of the user?

          Comment


          • #6
            That technique should still work fine. Here's an explicit example (RPG):
            Code:
                  /copy qcpylesrc,vvHspec                                                                                  
                 d sessVar       e ds                  extname(VVSESSDATA) qualified           
                  /include qcpylesrc,vvDspec                                                   
            
                   sessVar=vvUtility_getSessVar(VVSESSVAR);                                    
                   vvOut_toJsonPair('success:true,'+
                                    'ipAddress:'+%trim(sessVar.vvClientIP)+','+       
                                    'ibmIuser:'+%trim(sessVar.vvibmiuser));       
                   *inlr=*on;

            Comment


            • #7
              Code:
              /include qcpylesrc,vvHspec
              
              d sessDS e ds extname(vvSessData) qualified
              
              /include qcpylesrc,vvDspec
              
              SessDS = vvUtility_getSessVar(VVSESSVAR);
              userIP = sessDS.vvClientIP;
              In debug, my sessDS looks like this... as you can see, many fields are blank. The new online documentation says it's "depreciated"?


              SESSDS
              VVSESSID = SZEST51FHG4NPVRYDT1LEKYBMDHQWCISEVUP8KZLN15JXR6LV6 7ZHXL1TD0IDLU8
              VVTS_LOGIN = 2020-05-18-10.56.38.750000
              VVTS_ACT = 2020-05-18-10.56.43.639000
              VVUSRID = 000001020.
              VVENVID = 000001001.
              VVMETHOD = IBMI
              VVSPLAUTH =
              VVMODE = desktop
              VVTOKEN = t8hCOD6y8H5Y0e4iOjS8QijzaCuYMQLp
              VVLIBLIST = VALENCE52P VVAPPS50 ASTHHOBJ ASTDTA WQ_TBF
              VVIBMIUSER =
              VVCLIENTIP =
              VVNEXTPOLL =
              VVLNGID =
              VVLOCK =
              VVLOGINID =
              Last edited by gwilburn; 05-18-2020, 10:08 AM.

              Comment


              • #8
                Deprecated, but it still works.

                Have you tried recompiling your program? VVSESSDATA.VVLIBLIST was expanded to support more libraries in 5.2.20190424.0 (capacity increased from 46 to 250). The fact that you're seeing blanks after VVLIBLIST suggests it's still using the old file structure. Recompiling the program should fix that.

                Comment


                • #9
                  I've recompiled the program many times... but I just checked my compile listing.. it's pulling VVSESSDATA from library VALENCE51P. UGH!

                  I have RDi adding my libraries at startup...

                  This works now that I have compiled using the correct library... Thanks.

                  Should i worry about the depreciated value?

                  BTW - there's an SQL statement to get some of this information

                  Comment


                  • #10
                    Ah, the old library list problem. Glad you got it sorted out.

                    This approach is only deprecated because of that fact that file structure changes to VVSESSDATA force you to recompile your program. We'll keep supporting it, but using SQL or other procedures to get at the value is a little cleaner.

                    Comment

                    Working...
                    X