Created
October 6, 2014 22:48
-
-
Save ronnieduke/42fa80a29bf46369a329 to your computer and use it in GitHub Desktop.
Free service for geo location
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfif NOT StructKeyExists(cookie, "mylat") AND NOT StructKeyExists(cookie, "mylon")> | |
<cfparam name="country" default="US"> | |
<cfparam name="results" default=""> | |
<cftry> | |
<cfhttp url="http://freegeoip.net/xml/#cgi.remote_addr#" name="results" method="get" delimiter="#chr(10)#" timeout="10" /> | |
<cfset colname = results.columnlist> <!--- there's only one column and its name isn't something we can reference it by ---> | |
<cfset x = 0> | |
<cfset a = []> | |
<cfif IsQuery(results)> | |
<cfloop query="#results#"> | |
<cfset x = x + 1> | |
<cfset a[x] = results[colname]> | |
<cfif a[x] contains "Latitude"> | |
<cfset mylat = REReplaceNoCase(a[x], "<[^[:space:]][^>]*>", "", "ALL")> | |
</cfif> | |
<cfif a[x] contains "Longitude"> | |
<cfset mylon = REReplaceNoCase(a[x], "<[^[:space:]][^>]*>", "", "ALL")> | |
</cfif> | |
<cfif a[x] contains "CountryCode"> | |
<cfset country = REReplaceNoCase(a[x], "<[^[:space:]][^>]*>", "", "ALL")> | |
</cfif> | |
</cfloop> | |
</cfif> | |
<cfcatch type="any"> | |
<!--- <cfdump var="#cfcatch#" abort="true"> ---> | |
</cfcatch> | |
</cftry> | |
<!--- Cookie Time! ---> | |
<cfcookie name="mylat" value="#mylat#"> | |
<cfcookie name="mylon" value="#mylon#"> | |
<cfcookie name="myCountry" value="#country#"> | |
</cfif> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment