Share this Page URL
Help

Chapter 17. Working with Sessions > Using Client Variables - Pg. 391

Working with Sessions The DOMAIN attribute is commonly misunderstood. Sometimes, people assume that you can use it to specify other domains with which to share the cookies. DOMAIN, however, can be used only to specify whether to share the cookies with other servers in the same domain. 391 Sharing Cookies with Other Applications Because cookies are not a ColdFusion-specific feature, cookies set with, say, Active Server Pages are visible in ColdFusion's COOKIE scope, and cookies set with <CFCOOKIE> are visible to other applications, such as PHP, Perl, or JavaServer Pages. The browser doesn't know which language is powering which pages. All it cares about is whether the requirements for the domain, path, se- curity, and expiration have been met. If so, it makes the cookie available to the server. TIP If you find that cookies set in another language don't seem to be visible to ColdFusion, the problem might be the path part of the cookie. For instance, whereas ColdFusion sets the path to / by default so that the cookie is visible to all pages on the server, JavaScript sets the path to match that of the current page by default. Try setting the path part of the cookie to / so that it will behave more like one set with ColdFusion. The syntax to do this varies from language to language. Cookie Limitations There are some pretty serious restrictions on what you can store in cookies: · Only simple strings can be stored.Because dates and numbers can be expressed as strings, you can store them as cookies. But no ColdFusion-specific data types, such as arrays and structures, can be specified as the value for a cookie. · The cookie specification establishes that a maximum of 20 cookies can be set within any one domain.This prevents cookies from eventually taking up a lot of hard drive space. Browsers might or might not choose to enforce this limit. · Each cookie can be a maximum of only 4 Kbytes in length.The name of the cookie is considered part of its length. · According to the original specification, the browser is not obligated to store more than 300 cook- ies (total, considering all cookies set by all the world's servers together). The browser can delete the least recently used cookie when the 300-cookie limit has been reached. That said, many modern browsers choose not to enforce this limit. Using Client Variables Client variables are similar to cookies, except that they are stored on the server, rather than on the client (browser) machine. In many situations, you can use the two almost interchangeably. So, because you're already familiar with cookies, learning how to use client variables will be a snap. Instead of using the COOKIE prefix before a variable name, you simply use the CLIENT prefix. Okay, there's a little bit more to it than that. But not much. Before you can use the CLIENT prefix, you must enable ColdFusion's Client Management feature. See the section "Enabling Client Variables," later in this chapter. NOTE