Web application, getting the IP-Adress

Hi,

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.

Thanks in advance
Mabbi

Hi Marco,

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.

Hi Ricardo,

thank you for your response providing a starting point for me to dig into this.
Feedback to be delivered somewhere soon…

greets Marco

1 Like

Maybe you can just start with the Session.RemoteAddress property, and start using the headers only if needed. That could be enough for your scenario.

I do similar in one of my web apps.

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.

@Rich H:

is it possible to get some of your code snippets in here ?
Right now, i am still stuck with my application.

Thanks in advance,

Mabbi

Hi,

i got it working now, thanks for all of your help.

As Rich and Ricardo supposed i now store the Session.Identifier and Session.RemoteAddress in an sql-Database with a UserID and a timestamp.

Works fine for me, thanks for your help.

Greetings…Mabbi