10.07.2015 Views

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

16CHAPTER 1 ■ THE CGI MODULECookie IngredientsCookies consist of up <strong>to</strong> the following six parameters:• Name: This is the name of the cookie itself and is the only required parameter fora cookie.• Value: The value of a cookie is an optional item that contains the object or subject ofthe cookie. In other words, if you have a cookie with a name of sessionid, the value forthat sessionid might be 515093028943.• Domain: The domain parameter refers <strong>to</strong> the Internet domain within which thecookie is valid. Cookies are valid only within the domain in which they are set. Forexample, as an opera<strong>to</strong>r of example.com, you cannot read cookies that are tied <strong>to</strong> thedomain example.net.• Secure: The secure parameter refers <strong>to</strong> whether or not the cookie will be transmittedover an unsecure connection; that is, a connection that doesn’t use SSL. The default forthis parameter is off, meaning that cookies can be transmitted over SSL and non-SSLconnections alike.• Path: The path parameter further refines the area of the domain in which the cookieis valid. For example, a cookie with a path of /shoppingcart will be sent only <strong>to</strong>pages below /shoppingcart within the domain. That cookie would be sent <strong>to</strong>http://www.example.com/shoppingcart/checkout.cgi, but would not be sent <strong>to</strong>http://www.example.com/index.html, since index.html is not hierarchically belowthe /shoppingcart path in the URL.• Expiration date: The expiration date is the time at which the cookie will no longer bevalid. If no expiration date is set, or—and this is important—if the expiration date is setincorrectly, the cookie will expire at the close of the browser session. Some browserswon’t accept the cookie at all if the expiration date is not set correctly. The format forthe expiration date is specific and is as follows: Weekday, DD-MM-YYYY HH:MM:SS GMT.■Tip To clear a cookie, it's usually sufficient <strong>to</strong> set the value <strong>to</strong> null, or "".Cookie LimitationsThe following are some inherent limitations set by the cookie standard itself:• A 4KB <strong>to</strong>tal size for any single cookie• A <strong>to</strong>tal of 300 cookies s<strong>to</strong>red by a browser• A <strong>to</strong>tal of 20 cookies for any given server or domainWhile some of these limitations are merely recommendations, it’s a good idea <strong>to</strong> keepthese in mind when working with cookies. In addition, although not required, it is recommendedthat elements within a cookie be properly encoded. Usually, this means escaping

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!