Link to home
Start Free TrialLog in
Avatar of mmc98dl1
mmc98dl1Flag for Australia

asked on

url.var

Hi,

I have used url.var with no problem until now.

It works fine with urls in the following format -
/index.cfm?var=10&var2=20

But not for urls in this format -
/index.cfm/var/10/var2/20

How do i reference the value in the latter format?

thanks
Avatar of anandkp
anandkp
Flag of India image

Hi there,

the Url needs to be in the format "/index.cfm?var=10&var2=20"

how could u get the url in the other format ...
/index.cfm/var/10/var2/20

???
& even if u manage to get in the 2nd format - the var variable cannot be assigned the value 10 ...

but still if u want to go with the 2nd format - u can use listgetat function ...

let me know
K'Rgds
Anand

Avatar of mmc98dl1

ASKER

example:

http://www.computers-online.uk.com/osb/showitem.cfm/Category/4

use this ver:

http://www.computers-online.uk.com/osb/showitem.cfm?Category=4

you will see 4 appear in the title tag.

I need the 4 to appear when the url contains the / not ?
Hi there ...

I am wondering how could u access the value of the variable category when used with a "/"

can u provide me with a eg ...

i know - u must be thinking this is wierd -
but if i can see a sample code ...

awaiting
Thanx,

K'Rgds
Anand
unfortunately I cant tell you how this example works. I take you looked at the examples I have given you and you can see it works.

I dont know how the code is written as it comes from a package that has all code compiled - and would involve  time to break.
Avatar of DBrown
DBrown

Give this a try, any problems just yell...


PAGE 1
TEST.CFM

<cfparam name="attributes.delimiter" default="/">
<cfset query_string_length=Len(cgi.path_info) - Len(cgi.script_name)>
<cfif #query_string_length# neq 0>
<cfset query_string=Right(cgi.path_info, query_string_length)>
<cfset items=ListLen(query_string, attributes.delimiter)>
<cfif items MOD 2 Is 0>
<cfloop from="1" to="#items#" step="2" index="i">
<cfset i1=ListGetAt(query_string, i, attributes.delimiter)>
<cfset i2=ListGetAt(query_string, i + 1, attributes.delimiter)>
<cfparam name="url.#i1#" default="#i2#">
</cfloop>
</cfif>
</cfif>

<A HREF="http://66.27.8.253/test2.cfm/action/delete">Test</A>

PAGE 2

TEST2.CFM

<CFOUTPUT>
#url.action#
</CFOUTPUT>
Hi DBrown ..

this is cool ... indeed works & has to work ...

but i was thinking - probably there would be some settings in CFAplication - to change ur querystriing delimeter from the normal "?&=" to "/" ...

thanx for letting me know :)

K'Rgds
Anand
ASKER CERTIFIED SOLUTION
Avatar of DBrown
DBrown

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yap i figured that one out ...

but tell me one thing - what would happen if the no. of elements r not even.

it lets say i have abc.cfm/var1/1/var2/2/var3

in this case - what would be the result & how efficient it would be -

also to consider the eg of -
abc.cfm/var1/var2/2/var3
now in the above case the value of var1 is removed & still the things r not in the proper way ...

can u explain me this - [if u dont mind]

awaiting

K'Rgds
Anand
You would get an error, but that would be your fault :-) for improper coding....
or down to user error.

DBrown, this is very good, and may be the way my app does it, but I dont want to have to add this into my code. OSB (the store app from bizwebcrafter.com) must do i somehow, and I would like to use the var within the scope of their program.

I do see where you are coming from though - looks good. I imagine though that they used a cfm in built fund? Is there no such thing? I know you can change url's using ASP and apache server.......
All url's unless coded that way will use ?&= for the passing of variables in the URL. I am not aware of any configurations for apache to do such a thing. You can do the same thing in ASP, but I could not tell you how. And as far as user error, they should get an error page if they try and hack the url variables.



Best of luck


Doug
Hi DBrown,

I understand the error would be thrown - but i what i meant was that if the user while brwsing tries to change these variables then what ...

the coding is proper ... but lets say - the user changes it then ???

K'Rgds
Anand
That is what I mean, if the user tries to hack the URL, then they "should" get an error page.
It is not suppose to stop someone from hacking a URL, it is only for making the URL search engine safe. that is what <cfqueryparam> is for.


Doug
ok - i get u ...

thanx buddy ...

K'Rgds
Anand
Good job on this one Doug.  

:)
KWK
This is the famous custom tag to do this.

cf_Urlattributes

Search for it on developer's exchange....

Jimmy
interesting, thanks a ton for telling me about this, I dont require it any more, but the points go to Doug, I hope this is useful to other people in the future.