Link to home
Start Free TrialLog in
Avatar of SiriusPhil
SiriusPhil

asked on

Pass a URL as a variable in the URL

Is it possible to pass a URL as a variable in the URL?  If so, how would I do it?

Phil Hayes
Avatar of Zyloch
Zyloch
Flag of United States of America image

Hi SiriusPhil,

What do you mean? Like:

http://www.example.com/url.php?url=http://someotherexample.com/

? Yes, that's possible and you would get it out of the URL just like any other GET variable. I have no idea about ColdFusion syntax but it would be like that. Just make sure to URLEncode the URL first.

Regards,
Zyloch
Avatar of trailblazzyr55
trailblazzyr55

yeah it's possible

Like this

startpage.cfm
----------------------

<cfset MyVarr = "Http://www.yourdomain.cfm">

<form name="myform" action="actionpage.cfm?VariableOne=#MyVarr#" method="post">

...form elements...

...submit button....

</form>

actionpage.cfm
------------------------------------------
<cfparam name="url.VariableOne" default="">

<cfoutput>

My URL Variable: #Url.VariableOne#<br>

<a href="#Url.VariableOne#"> Here's the link</a>

</cfoutput>
URLEncodedFormat(string [, charset ])

oops forgot to account for the URLEncodedFormat

here:

startpage.cfm
----------------------

<cfset MyVarr = "http://www.yourdomain.cfm">

<form name="myform" action="actionpage.cfm?VariableOne=#URLEncodedFormat(MyVarr)#" method="post">

...form elements...

...submit button....

</form>

actionpage.cfm
------------------------------------------
<cfparam name="URL.VariableOne" default="">
<cfset MyVarr = URLDecode(URL.VariableOne)>

<cfoutput>

My URL Variable: #MyVarr#<br>

<a href="#MyVarr#"> Here's the link</a>

</cfoutput>


there ya go ;o)
~trail
Avatar of SiriusPhil

ASKER

Woops..

Forgot to tell you one thing...

Some of the URL's I want to send as variables have variables in them too.

Can I send somethong like...

http://foo.com?id=1

through a URL variable?



ASKER CERTIFIED SOLUTION
Avatar of mrichmon
mrichmon

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
here:

startpage.cfm
----------------------
<cfset next = SomethingElse">
<cfset mysecond = "Something">
<cfset MyVarr = "http://www.yourdomain.cfm?mySecond=#SecondVarr#&next=#next#">

<cfset extra = "AdditionalVariables">

<form name="myform" action="actionpage.cfm?MyURL=#URLEncodedFormat(MyVarr)#&extra=#extra#" method="post">

...form elements...

...submit button....

</form>

actionpage.cfm
------------------------------------------
<cfparam name="URL.MyURL" default="">
<cfset MyVarr = URLDecode(URL.MyURL)>

<cfparam name="URL.extra" default="">
<cfset extra = URL.extra>

<cfoutput>

My URL Variable: #MyVarr#<br>
My Extra Variables: #extra#<br>

<a href="#MyVarr#"> Here's the link</a>

</cfoutput>
yeah good catch mrichmon, pass any additional url variables before the passedURL

also you make a good point about accessing variables in the passed url.

between the two posts that should cover what you are looking to do ;o)

~trail