Advertisement
snarfblat

Geolocation

Oct 6th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. <cfparam name="country" default="US">
  2. <cfparam name="results" default="">
  3.  
  4. <cftry>
  5.  
  6. <cfhttp url="http://freegeoip.net/xml/#cgi.remote_addr#" name="results" method="get" delimiter="#chr(10)#" timeout="10" />
  7.  
  8. <cfset colname = results.columnlist> <!--- there's only one column and its name isn't something we can reference it by --->
  9. <cfset x = 0>
  10. <cfset a = []>
  11.  
  12. <cfif IsQuery(results)>
  13. <cfloop query="#results#">
  14. <cfset x = x + 1>
  15. <cfset a[x] = results[colname]>
  16.  
  17. <cfif a[x] contains "Latitude">
  18. <cfset mylat = REReplaceNoCase(a[x], "<[^[:space:]][^>]*>", "", "ALL")>
  19. </cfif>
  20.  
  21. <cfif a[x] contains "Longitude">
  22. <cfset mylon = REReplaceNoCase(a[x], "<[^[:space:]][^>]*>", "", "ALL")>
  23. </cfif>
  24.  
  25. <cfif a[x] contains "CountryCode">
  26. <cfset country = REReplaceNoCase(a[x], "<[^[:space:]][^>]*>", "", "ALL")>
  27. </cfif>
  28.  
  29. </cfloop>
  30. </cfif>
  31.  
  32. <cfif country eq "AU">
  33. <cflocation url="http://www.hearandlearn.com.au" addtoken="no">
  34. </cfif>
  35.  
  36. <cfcatch type="any">
  37. <!--- <cfdump var="#cfcatch#" abort="true"> --->
  38. </cfcatch>
  39.  
  40. </cftry>
  41.  
  42.  
  43. <!---
  44. Query
  45. Execution Time: 0 ms
  46. Record Count: 13
  47. Cached: No
  48. Lazy: No
  49. <?xml version=1.0 encoding=UTF-8?>
  50. 1 <Response>
  51. 2 <Ip>75.164.200.43</Ip>
  52. 3 <CountryCode>US</CountryCode>
  53. 4 <CountryName>United States</CountryName>
  54. 5 <RegionCode>OR</RegionCode>
  55. 6 <RegionName>Oregon</RegionName>
  56. 7 <City>Portland</City>
  57. 8 <ZipCode></ZipCode>
  58. 9 <Latitude>45.5234</Latitude>
  59. 10 <Longitude>-122.6762</Longitude>
  60. 11 <MetroCode>820</MetroCode>
  61. 12 <AreaCode>503</AreaCode>
  62. 13 </Response>
  63. --->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement