Solved

How to use result from CFSCRIPT in CFQUERY

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

832 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