i am trying to create a small web-application in XOJO.
It simply provides a login webpage where the user can submit various data he wants to submit.
I would like to store the Users-IP adress when he is submitting his data in addition to the User-provided-Data.
All Data is then stored in an sqlDB for later use.
Actually i have no idea how to get access to the IP-Adress of the connecting User ?
Can someone please help me with some basics here.
This really depends on how you’re deploying your app. For example, if there is a CDN in front of your web application, it will vary.
As an starting point:
Var ipHeaders() As String = Array("X-Forwarded-For", "Remote-Addr")
For Each ipHeader As String In ipHeaders
Var value As String = Header(ipHeader)
If value <> "" Then
Return value
End If
Next
Return RemoteAddress
This will try to find the IP in that specific order, you may want to adjust this to your needs. If it can’t be found in the headers, it will use the remote socket address.
Please note some proxies will return a list of comma-separated IPs.
In fact, I actually track the user through out their interaction on the web app and store it in a log table.
RemoteAddress would be their ip address, but in addition to storing that to a log in the db. I also store the session UUID which is Identifier and user name, datetime, anything I want to keep track of what they click on, just to name a few things.
to make all this work, I have a method that I supply the information to who then inserts into the database the log info.