Is there anything attached to the session that would allow me to capture the IP Address for users attempting to login to my web app? I have had a few attempts of logins and Im not sure where it’s coming from because my web apps is only in use by me currently. I just want to be able to capture an IP address and log it so that I can see whats going on.
Use this in your Session.open Event it should work.
message can be a string passed to this method if you want to use it for other things.
Dim i as integer
Dim B as Boolean
Dim F,dbFile as FolderItem
Dim Dt as New Date
Dim S,R,C as String
R = Session.RemoteAddress
C = Dt.ShortDate + " - " + Dt.LongTime + ". Address " + R + ", " + message + EndOfLine
F = SpecialFolder.Documents
F = F.Child(“SessionAccessLog.txt”)
If F <> NIL AND F.exists then
Dim t as TextOutputStream = TextOutputStream.Append(f)
Catch e as IOException
Awesome! Thank you so much. That works for what I need!
As reminder this only works with Standalone or .CGI Webapps.
Due to the fact that in wildlife a XOJO Web App is placed behind a Reverse Proxy you should consider that you only would see the IP address of your reverse. You have to set (on the Reverse Proxy) and to examine (in your Web app) HTTP X-Headers for the remote IP Address then.
An IP-address might change when a user logs in from a mobile device. When such a device is switching from cell-tower to cell-tower, the IP-address will not be the same.
Wouldn’t that drop connections on services like skype?
Nope. I tested this with my smartphone by driving from Maastricht (City in the southern part of The Netherlands) to Eemshaven (City in the northern part in The Netherlands). It’s about a 4 hour trip. Yeah, The Netherlands is a small country. My IP address changed many times while hopping from cell-tower to cell-tower.
And since I have Whatsapp audio and Skype conversations with my foreign friends quite often I know that it doesn’t drop connections.