Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Auto append url variables on every links

Status
Not open for further replies.

hansolo

IS-IT--Management
Feb 5, 2000
14
MY
Currently my website is using aSession.cfm framework which needs to append session variables to every links. It is possible to automatically append a the variables to every url links without manually keyin the variables?

Thanks
Hansolo
 
Hi hansolo,


You might consider using 'application.cfm', in which you put all your variables. You can access them all over the site without having to add all the info at the end of the URL.

You best store the info in a cookie.
An example of such an 'application.cfm' is:

<CFAPPLICATION NAME=&quot;testing&quot;
CLIENTMANAGEMENT=&quot;Yes&quot;
SESSIONMANAGEMENT=&quot;Yes&quot;
SETCLIENTCOOKIES=&quot;Yes&quot;
CLIENTSTORAGE=&quot;cookie&quot;>


<CFSET mydatasource= &quot;customers&quot;>

<CFIF IsDefined(&quot;customerID&quot;)>
<cfset customerID=#customerID#>
<CFELSE>
<CFLOCATION URL=&quot;login.cfm&quot; ADDTOKEN=&quot;No&quot;>
</CFIF>


---------

In your CFM files you can easy refer to your datasource name and customerID like:

<cfquery name=&quot;customers&quot; datasource=&quot;#mydatasource#&quot;>
select * from customers
where customer_ID =#customerID #


Hoped this helped you out.
Regards
Bram
 
Bram, thanks for the tips.

the following examples show how my current codes look like

<A href=&quot;linkX.cfm?<cfoutput>#cf_aSession#</cfoutput>&quot;>
link X</A>
<A href=&quot;linkY.cfm?<cfoutput>#cf_aSession#</cfoutput>&quot;>
link Y</A>
<A href=&quot;linkZ.cfm?<cfoutput>#cf_aSession#</cfoutput>&quot;>
link Z</A>

My codes should look like the following if I store the variable in application.cfm

<A href=&quot;linkX.cfm?&quot;>link X</A>
<A href=&quot;linkY.cfm?&quot;>link Y</A>
<A href=&quot;linkZ.cfm?&quot;>link Z</A>

But how to append the session variables to the url link once they are inside application.cfm?

Your help is much appreciated
Hansolo
 
Hi hansolo,

You have two options.

First:
------------
You still want to add the info at the end of the URL than you do:

<cfoutput>
<A href=&quot;linkX.cfm?customer=#customerID#&quot;>link X</A>
<A href=&quot;linkY.cfm?customer=#customerID#&quot;>link Y</A>
<A href=&quot;linkZ.cfm?customer=#customerID#&quot;>link Z</A>
</cfoutput>

On page linkx.cfm you can output the variable by using:

<cfoutput>#customer#</cfoutput>

Second:
------------

Linkx.cfm refers to a new webpage where you want to do something with the URL variable I guess.

Let's say you want to display the full name of the person (customer) who logged in on your website, you stored the customerID into the application.cfm file and on page: linkx.cfm you want to retrieve his info from the database (doing a cfquery)>.

Because the customers ID is stored in the application.cfm file you do not need to add it to the URL.

Just click on linkx.cfm and put an <cfoutput>#customer#</cfoutput>, you'll see that the customer ID (stored as a session variable) will be displayed!


Tip: Don't forget to check whether the customer has logged in on the website (otherwise you have no ID number).
This is done by checking the existance:

Like:

<cfif Isdefined(customerID)>
<cfset customerID=#customerID#>
<cfelse>
<cflocation url=login.cfm
</cfif>

With kind regards
bram




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top