View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Cookies and Session Variables by Meet Patel

Overview of Cookies and Session Variables

Cookies

Cookies are small piece of text stored on the user’s computer by websites. They can also be used for session management. For example the contents of shopping cart are stored in virtual cookie where the items are stored. They can be also implemented to check for creditability.

Creating and Adding a Cookie

userCookie := HTTPCookie named: 'logincookie' value: (userName).
userCookie expireAfterDays: 5.
response addCookie: userCookie.


Cookie name = HTTPCookie named: name value: the contents of the cookie
userCookie := HTTPCookie named: 'logincookie' value: (userName).

(Name of the cookie) expireAfterDays: # of days.
userCookie expireAfterDays: 5.

Adds the cookie: cookie name
response addCookie: userCookie.


Retrieving the information from a Cookie

userCookie := request cookieValueAt: 'logincookie'.
response write: ('Hello ',userCookie').


Variable name = request cookieValueAt: (name of the cookie)
userCookie := request cookieValueAt: 'logincookie'.

response write: (html tags, variable name, html tags)
response write: ('Hello ',userCookie).

Session

Session variables allow you to store user specific data amongst the page but it’s different from cookie as in where it lets you store multiple items in a session.

session at: ‘something’ put: somethingfromeach

It can be set for each user and individual after certain action is performed then the session variable is set. For example, it can be checked it a session is created for a user and check to see if that user is logged in.

session at: ‘something’ ifAbsent: [do something]
session at: ‘something’ ifPresent: [do something]

Since session can store an instance of a class it can be retrieved very easily. For example if the session holds an instance of User class.

response write: ( something userid, ‘,’ something password).

Link to this Page