Solved

How to use result from CFSCRIPT in CFQUERY

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

829 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