dsk1234
asked on
Cfparam and Findnocase in Coldfusion
Hi All,
We have the following code in coldfusion that will accept single Ip address.
//Setting single IP Address
<cfparam name="IPAddress" default="xx.x.x.xxx">
//Checking condition
<cfif cgi.server_port_secure neq 1 and FindNoCase("#IPAddress#", cgi.remote_addr, 1) neq 1>
do something
<cfelse>
do something
</cfif>
I need to modify the above code with set of multiple static IP addresses in cfparam and checking those IPAddresses in FindNocase? How can I achieve this?
Thanks in Advance
We have the following code in coldfusion that will accept single Ip address.
//Setting single IP Address
<cfparam name="IPAddress" default="xx.x.x.xxx">
//Checking condition
<cfif cgi.server_port_secure neq 1 and FindNoCase("#IPAddress#", cgi.remote_addr, 1) neq 1>
do something
<cfelse>
do something
</cfif>
I need to modify the above code with set of multiple static IP addresses in cfparam and checking those IPAddresses in FindNocase? How can I achieve this?
Thanks in Advance
ASKER
Thanks for the quick response and will get back to you.
ASKER
Hi,
we have another 2 pages where we are referring the IPAddress(es) with the following code
<cfscript>
function f1()
{
if(FindNoCase(#IPAddress#, cgi.remote_addr, 1) eq 1)
{
do something
}
else
{
do something
}
}
</cfscript>
So I believe we need to change the above code with listFind as per your suggestion to accomodate multiple static Ip addresses.Is it correct?
Since we are referring the IPAddresses in another 2 pages, do we still need to use cfset while assigning multple static IP addresses ?
we have another 2 pages where we are referring the IPAddress(es) with the following code
<cfscript>
function f1()
{
if(FindNoCase(#IPAddress#,
{
do something
}
else
{
do something
}
}
</cfscript>
So I believe we need to change the above code with listFind as per your suggestion to accomodate multiple static Ip addresses.Is it correct?
Since we are referring the IPAddresses in another 2 pages, do we still need to use cfset while assigning multple static IP addresses ?
> we have another 2 pages where we are referring the IPAddress(es) with the following code
> So I believe we need to change the above code with listFind
Yes
> Since we are referring the IPAddresses in another 2 pages, do we still need to
> use cfset while assigning multple static IP addresses ?
Not sure I understand the question. Are you using the same list of multiple IP addresses on all 3 pages?
> So I believe we need to change the above code with listFind
Yes
> Since we are referring the IPAddresses in another 2 pages, do we still need to
> use cfset while assigning multple static IP addresses ?
Not sure I understand the question. Are you using the same list of multiple IP addresses on all 3 pages?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Yeah, if it's the same the list (I wasn't quite clear on the setup). I was thinking if the function does the same thing in all 3 pages, it should also be stored in a central location. So you don't have the same code repeated in multiple places.
ASKER
At present the following code will accecpt single static IP address and based on this IP address we are checking condition and redirecting to specific Url.
I was told that the application should now handle multple static IP addresses.So I searched for the IPAddress instance in the application and found in the follwing 3 places.
The following code should be changed accordingly to handle multiple static Ip addresses.
Existing code
1)app.cfm //Global settings page
<cfparam name="IPAddress" default="xx.x.x.xxx"> //single IP Address
<cfif cgi.server_port_secure neq 1 and FindNoCase("#IPAddress#", cgi.remote_addr, 1) neq 1> //Checking condition
do something
<cfelse>
do something
</cfif>
2)RefPage1.cfm
<cfscript>
function f1()
{
if(FindNoCase(#IPAddress#, cgi.remote_addr, 1) eq 1)
{
do something
}
else
{
do something
}
}
</cfscript>
3)RefPage2.cfm
<cfscript>
function f1()
{
if(FindNoCase(#IPAddress#, cgi.remote_addr, 1) eq 1)
{
do something
}
else
{
do something
}
}
</cfscript>
I was told that the application should now handle multple static IP addresses.So I searched for the IPAddress instance in the application and found in the follwing 3 places.
The following code should be changed accordingly to handle multiple static Ip addresses.
Existing code
1)app.cfm //Global settings page
<cfparam name="IPAddress" default="xx.x.x.xxx"> //single IP Address
<cfif cgi.server_port_secure neq 1 and FindNoCase("#IPAddress#", cgi.remote_addr, 1) neq 1> //Checking condition
do something
<cfelse>
do something
</cfif>
2)RefPage1.cfm
<cfscript>
function f1()
{
if(FindNoCase(#IPAddress#,
{
do something
}
else
{
do something
}
}
</cfscript>
3)RefPage2.cfm
<cfscript>
function f1()
{
if(FindNoCase(#IPAddress#,
{
do something
}
else
{
do something
}
}
</cfscript>
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
> <cfif listFind("... IP address List....", cgi.remote_addr)>
I agree with the above suggestions. Just remember it's very important NOT to use <cfparam> to declare the list of ip addresses. Use cfset instead. Otherwise, a user could pass in whatever value they want through the url. Then they'd be declared an Administrator and have access to things they shouldn't...
ASKER
Thank you guys.Will get back to you on the above approach.
ASKER
Thank you guys.
<!--- set the list of static ip addresses to check for --->
<cfset ipAddressList = "127.0.0.1,192.168.1.1,...
<cfif listFind(ipAddressList, cgi.remote_addr)>
found cgi.remote_addr in list ...
<cfelse>
not found. do something else
</cfif>
> <cfparam name="IPAddress" default="xx.x.x.xxx">
Unless you need to pass the value from another page, I'd just use CFSET instead. Because using cfparam, someone could override the value by adding a new value onto the URL.
http://somesite.com/yourPage.cfm?ipaddress=xx.xxx.xxx.xxx