Solved

How to use result from CFSCRIPT in CFQUERY

Posted on 2008-06-19
2
303 Views
Last Modified: 2013-12-24
Hi,

I have  a script that captures a visitor's IP address, then converts it to a number.  This is so I can then lookup their city/region for personalization purposes on my site.  The site is not live yet, but I'm having an issue with using the returned value from the CFSCRIPT as a variable to query my DB.  Here's what the script looks like:

<CFSET visitorIP = "#CGI.Remote_Addr#">

 <cfscript>
   function Dot2LongIP(visitorIP)
   {
      if(arguments.visitorIP EQ "")
      {
        return 0;
      }
      else
      {
        ips = ListToArray( arguments.visitorIP, "." );
        return( ( 16777216 * ips[1] ) + ( 65536 * ips[2] ) + ( 256 * ips[3] ) + ips[4] );
      }
   }
</cfscript>

I need to use the resulting number to query a table in my DSN.  Right now, I have:

<cfset myIPNumber = #Dot2LongIP#>

But it's not working correctly - the returned value is "cfindex2ecfm1275582484$funcDOT2LONGIP@115e47a".

I only need the 1275582484 number out of that.

Any ideas?

Thanks in advance!

0
Comment
Question by:skodama2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 36

Accepted Solution

by:
SidFishes earned 500 total points
ID: 21826582
try this

 <cfscript>
   function Dot2LongIP(visitorIP)
   {
      if(arguments.visitorIP EQ "")
      {
        return 0;
      }
      else
      {
        ips = ListToArray( arguments.visitorIP, "." );
        return( ( 16777216 * ips[1] ) + ( 65536 * ips[2] ) + ( 256 * ips[3] ) + ips[4] );
      }
   }
</cfscript>


<CFSET visitorIP = Dot2LongIP(CGI.Remote_Addr)>

<cfdump var="#visitorIP#">
0
 

Author Closing Comment

by:skodama2
ID: 31468971
Thank you!  Pure magic!
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question