snarfblat

Free Geolocation with ColdFusion

Jun 23rd, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <cfhttp url="http://freegeoip.net/xml/#cgi.remote_addr#" name="results" method="get" delimiter="#chr(10)#" />
  2.  
  3. <cfset colname = results.columnlist> <!--- there's only one column and its name isn't something we can reference it by --->
  4. <cfset x = 0>
  5. <cfset a = []>
  6.  
  7. <!--- <cfdump var="#results#"> Uncomment this to see the list of everything you can check for. --->
  8.  
  9. <cfloop query="#results#">
  10.     <cfset x = x + 1>
  11.     <cfset a[x] = results[colname]>
  12.  
  13.     <cfif a[x] contains "Latitude">
  14.         <cfset mylat = REReplaceNoCase(a[x], "<[^[:space:]][^>]*>", "", "ALL")>
  15.     </cfif>
  16.  
  17.     <cfif a[x] contains "Longitude">
  18.         <cfset mylon = REReplaceNoCase(a[x], "<[^[:space:]][^>]*>", "", "ALL")>
  19.     </cfif>
  20.    
  21.     <cfif a[x] contains "CountryCode">
  22.         <cfset country = REReplaceNoCase(a[x], "<[^[:space:]][^>]*>", "", "ALL")>
  23.     </cfif>
  24.  
  25. </cfloop>
  26.  
  27. <cfif country eq "AU">
  28.     <cflocation url="http://www.someplaceelse.com" addtoken="no">
  29. </cfif>
Add Comment
Please, Sign In to add comment