asked on
Set SessionLookup=oConn.Execute("SELECT * FROM site_sessions WHERE session_ID="&Session.SessionID)
If Not SessionLookup.EOF Then
Session_ID=SessionLookup("session_ID")
Else
Set oXMLHTTPLocIP=CreateObject("MSXML2.ServerXMLHTTP")
LocIP="http://api.ipify.org/"
oXMLHTTPLocIP.Open "GET",LocIP,False
oXMLHTTPLocIP.Send
If oXMLHTTPLocIP.Status="200" Then
IP=oXMLHTTPLocIP.responseText
Set oXMLHTTPLoc=CreateObject("MSXML2.ServerXMLHTTP")
IP=oXMLHTTPLocIP.responseText
LocAPI="http://ip-api.com/json/"&IP&"?fields=countryCode,city"
oXMLHTTPLoc.Open "GET",LocAPI,False
oXMLHTTPLoc.Send
If oXMLHTTPLoc.Status="200" Then
GetTextFromUrlLoc=oXMLHTTPLoc.responseText
CityLoc=Replace(Split(Split(GetTextFromUrlLoc,",")(0),":")(1),"""","")
CountryLoc=Replace(Replace(Split(Split(GetTextFromUrlLoc,",")(1),":")(1),"""",""),"}","")
End If
End If
oConn.Execute("INSERT INTO site_sessions(session_ID,brand_ID,session_IP,session_geoCity,session_geoCountry,session_timezone,session_date,session_time) VALUES("&Session.SessionID&",'"&SubDomain("brand_ID")&"','"&IP&"','"&CityLoc&"','"&CountryLoc&"','"&Timezone()&"','"&Date()&"','"&Time()&"')")
Set NewSession=oConn.Execute("SELECT @@IDENTITY AS New_Session_ID")
Session_ID=Cstr(NewSession("New_Session_ID"))
End If