Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Get country from IP

    Dear All,

    I need to do the following with CF:

    When a user visits my website, I need to get his/her IP address and thus know the country he/she is browsing from.

    Is this possible?

    Kindly advise
    externalError Guest

  2. Similar Questions and Discussions

    1. Country of user
      Hi, Is that possible to understand which country is the user from his or her GSM operator in smartphones with .NET Compact Framework? Any help...
    2. Module for Country/Country Codes Lists
      Hi! My name is Shlomi Fish and I am a co-developer of the WWW::Form module: http://search.cpan.org/~bschmau/WWW-Form-1.13/ Benjamin Schmaus...
    3. Country
      How can I view visitors country using php/apache?
    4. getting country stats
      My client wants to see stats which tell him the number of hits he's getting from different countries. I'm coding page hit count stats myself in PHP...
    5. how to get the country ?
      from the IP of the request ?
  3. #2

    Default Re: Get country from IP

    [url]http://www.sustainablegis.com/projects/geoLocator/[/url]
    PaulH Guest

  4. #3

    Default Re: Get country from IP

    geoLocator did not work with me! Thanks anyway. I tried to code it as the
    following (I have a database with IP_FROM, IP_TO, and Country fields):
    <cfparam name='variables.ipnumber' default='0'> <cfparam name='variables.loc'
    default='n/a'> <cfset dsn = 'iplocation'> <cfif isdefined('form.sbmt') and
    len(form.ipaddress) gt 10> <cfset a = ListFirst(form.ipaddress,'.')> <cfset
    a_rest = ListRest(form.ipaddress, '.')> <cfset b = ListFirst(a_rest, '.')>
    <cfset b_rest = ListRest(a_rest, '.')> <cfset c = ListFirst(b_rest, '.')>
    <cfset c_rest = ListRest(b_rest,'.')> <cfset d = ListFirst(c_rest, '.')>
    <cfset ipnumber = a*(256*256*256) + b*(256*256) + c*256 + d> <cfquery
    datasource='#dsn#' name='q' maxrows='1'> SELECT country FROM iplocation
    WHERE ip_from <= #variables.ipnumber# AND ip_to >= #variables.ipnumber#
    </cfquery> <cfoutput query='q'><cfset variables.loc =
    '#q.country#'></cfoutput> </cfif> <cfform action='index.cfm' method='post'>
    <table> <tr> <td>IP Address</td> <td><cfinput type='text' name='ipaddress'
    size='20' required='yes' value='#cgi.remote_addr#'></td> </tr> <tr> <td>IP
    Number</td> <td><input type='text' name='ipnumber' disabled
    value='<cfoutput>#variables.ipnumber#</cfoutput>'></td> </tr> <tr>
    <td>Location</td> <td><input type='text' name='loc' disabled
    value='<cfoutput>#variables.loc#</cfoutput>'></td> </tr> <tr>
    <td>&amp;nbsp;</td> <td><input type='submit' name='sbmt' value='Calculate IP
    #'></td> </tr> </table> </cfform> but I still have a problem retreiving the IP
    using #CGI.remote_addr# if the machine is behind a router. Any solution to
    this? Kindly advise

    externalError Guest

  5. #4

    Default Re: Get country from IP

    why didn't geoLocator work?
    PaulH Guest

  6. #5

    Default Re: Get country from IP

    No idea. Could you give some tips on How to use it.

    Regards
    externalError Guest

  7. #6

    Default Re: Get country from IP

    it's outlined in the zip but:
    - place the InetAddressLocator.jar file in the cf install
    dir\wwwroot\web-inf\lib dir
    - to simplify things place the index.cfm (that's a simple testbed) and the
    geoLocator.cfc in the same dir & then edit this line in the index.cfm file:
    geoLocator=createobject("component","cfc.geoLocato r");
    to this:
    geoLocator=createobject("component","geoLocator");

    that's it.


    PaulH Guest

  8. #7

    Default Re: Get country from IP

    Well you can use Web Services, i dont think it's what you want but try it , In
    dreamweaver go Application window then press component then choose Web Services
    , after when you fined that , add this link
    [url]http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl[/url] in proxy genereter choose
    ColdFusion . and press ok ..... in cood panel add this code <cfinvoke
    webservice='http://ws.cdyne.com/ip2geo/ip2geo.asmx?wsdl' method='resolveIP'
    returnvariable='aIPInformation'> <cfinvokeargument name='IPaddress' value='put
    ip here'/> <cfinvokeargument name='licenseKey' value=''/> </cfinvoke>
    <cfoutput> #aIPInformation.country# #aIPInformation.stateProvince#
    #aIPInformation.organization# #aIPInformation.city# </cfoutput> i hope it
    will work

    eddymilner Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139