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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client Vars 2

Status
Not open for further replies.

dasniper

Programmer
Apr 11, 2001
25
0
0
US
I'm thinking of moving my application to use CLient vars.

I know you can specify them into a database using <cfapplication clientmanagement=&quot;Yes&quot; datasource=&quot;DSN&quot;>

But, how do I get them to work?

Is it as easy as looking for the CFID, and then relegating that CFID to a user in the database through a Join between CDATA and a user table?

Or can CLient Vars not be used to track returning visitors?
 
Hey dasniper,

Once you enable client variables in your <cfapplication> tag, you can create and reference them like any other variable.

<cfset client.username=&quot;john&quot;>
<cfif client.password is &quot;apple&quot;>
.....
</cfif>

CF will manage them behind the scenes for you so you don't have to worry about the cfid & cftoken variables. The one exception to this is if you want to code your application to work even if the visitor has cookies disabled. In this case, you simply have to pass the cfid & cftoken via url variables like this.

<a href=&quot;index.cfm?cfid=#cfid#&cftoken=#cftoken#&quot;>Page</a>
<form method=&quot;post&quot; action=&quot;index.cfm?cfid=#cfid#&cftoken=#cftoken#&quot;>

This will allow for CF to receive the cfid & token without cookies and keep track of the current client variables. The client variables will be stored for a period of time based on a setting in the Cf administrator which can be anywhere from several days to several months. As long as the visitor comes back to your site within this time frame, the client variables will not get deleted.

Choosing to store client variables in a database doesn't affect your application in how you code it but more in terms of how it runs on the server. Using the registry to store client variables (default) can cause the server to crash if you have high traffic and the registry fills up faster than CF times out the client variables. Storing them in a database can cause your application to not function if the database becomes unavailable. Using a database though allows you to maintain client information across multiple servers in a clustered environment if all servers point to the same database. This is more of an &quot;architectural&quot; decision and doesn't require you to code anything differently.

Hope this helps,
GJ
 
Thanks GunJack, it was helpful.

What I was thinking of though was a way to personalize the site for the visitor.

If a user comes to the site, then the app sees if they have a cookie, with CFID in it. If so, then the app knows that they were here before. Now, can I link that CFID to a user database that says &quot;Hey, for the User CFID of 100, I know they like the screen to be Purple and text to be white&quot;?

Or, let's say that a user comes to the site, but they don't have cookies for whatever reason, but they have signed in. Can they then authenticate to the app, and then the app would look them up in CGLOBAL and send them their CFID and CFTOKEN, so that their personal preferences would then kick in?

Or am I just missing the point of CLient Vars?

BTW, you're right about the registry filling up. I did that before. Crashed the machine and cfexec would go to 100% utilization.
 
You're on the right track but don't worry about the cfid & cftoken, they are just there for CF's use. I would use the isdefined() function to see if they have a client variable and create one if they didn't. Since CF handles looking up the cfid & token for you, just think of it as you already know who they are and just read their client variables as if they were pulled from a database for you. Here's an example.

<cfif NOT isdefined(&quot;client.hasProfile&quot;>
<!--- Initialize all client info here --->
<cfinclude template=&quot;initializeClientSettings.cfm&quot;>
<cfelse>
<cfoutput>#client.Name# - Last Visit #client.lastVisit#</cfoutput><p>
<cfif client.hasAccess is &quot;yes&quot;><a href=&quot;PrivatePage.cfm&quot;>Private Stuff</cfif>
<a href=&quot;OtherStuff.cfm&quot;>Main Stuff</a>
</cfif>

Btw, client.lastVisit is a variable CF maintains automatically for you.

Hope this helps,
GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top