Solved

How to use result from CFSCRIPT in CFQUERY

Posted on 2008-06-19
2
291 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
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Is IHttpActionResult a promise pattern? 2 37
Problem to picture file 3 42
HTML page and JavaScript 2 56
cookies analysis tools 2 29
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
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 …
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now