EasyCFM.COM ColdFusion Forums / ASP to CFML / Calculating long ip it it's checking in db

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Calculating long ip it it's checking in db

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

Adept
03-16-2004 @ 2:13 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 1
Joined: Mar 2004

Help please to do follow thing in cfml... PLEASE.


<%@LANGUAGE="JavaScript"%>
<%
function getCountry(){
   var ip=new String(Request.ServerVariables("REMOTE_ADDR"));
   var n=new Array();
       n=ip.split(/\./);
  var ip_long=Number(n[0])*256*256*256+Number(n[1])*256*256+Number(n[2])*256+Number(n[3]);

  var connection="Driver={Microsoft Access Driver (*.mdb)};DBQ="+Server.MapPath("\\detect\\country2ip.mdb");
   var RS = Server.CreateObject("adodb.recordset");
     RS.Open("SELECT * FROM result WHERE (result.start<="+ip_long+" AND result.end>
="+ip_long+");", connection, 2, 3);

   var country=new String();
   if (! RS.EOF){
      country=RS("country");
   }else{
      country="other";
   }

   return country;
}

   if (getCountry() == 'KZ'){
      Response.Redirect("kz.htm");
   }
%>


Thanks a lot...

CJ
03-24-2004 @ 6:31 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Administrator
Posts: 4262
Joined: Oct 2002

could probably be done cleaner...but this should be about the same (minus the dsn-less connection)


<cfscript>
     ip = cgi.remote_addr;
     n = listToArray(ip, '.');
     
     ip_long = n[1]*256*256*256 + n[2]*256*256 + n[3]*256 + n[4];
</cfscript>

<cfquery name="myQuery" datasource="myDSN">
     SELECT *
     FROM result
     WHERE (result.start <= #ip_long# AND result.end >= #ip_long#)
</cfquery>

<cfif myQuery.recordCount>
     <cfset variables.country = myQuery.country>
<cfelse>
     <cfset variables.country = "other">
</cfif>

<cfif variables.country IS "KZ">
     <cflocation URL="kz.htm" addtoken="no">
</cfif>




-CJ-
@ #coldfusion/DALNet
http://charlie.griefer.com


Website Designed and Developed by Pablo Varando.