Deutsch English
Home
About tdbengine
Newsletter
Download
Helpware
Forum
Chat
Documentation
Basic Course
Function reference
HOWTO...?
Snippets
Projects
Links
Benchmarks
Bug Reporting
Support request
 
Home    Overview    Search    Impressum    Contact    Members
How to work with cookies?
To put some light to the cookie darkness we recomend you reading this mini howtos.


Cookie, an unknown creature.
Unfortunately cookies aren't products of a bakery but little strings saved on youre PC's harddisk unless you delete them(or they validity expires).
The informations saved on youre PC will be only transfered to the server they came from.

Cookies aren't computer programs and mustn't damage files on youre PC.


Here! Have a cookie.
To set a cookie at user's PC you have to transfer it before all other outputs in HTTP-Header.
Therefor just place a line with following structure before "content-type" line:

set-cookie: <NAME>=<VALUE>;

or

set-cookie: <NAME>=<VALUE>; expires=<RFC-DATE>; path=<PATH>;


Example:

...
CGIWriteLn('Set-Cookie: User=John Q. Public; expires=Sunday, 01-Dec-2099 12:00:00 GMT; path=/;')
CGIWriteLn('Set-Cookie: Birthday=02.01.1960; expires=Sunday, 01-Dec-2099 12:00:00 GMT; path=/;')
CGIWriteLn('content-type: text/html')
CGIWriteLn('')
// untill here it was all HTTP-Header the following part is the HTML page.

CGIWriteLn('<html>')
CGIWriteLn('<head><title>cookie-test</title></head>')
CGIWriteLn('<body>Cookie set</body>')
CGIWriteLn('</html>')
...

This example sets two ckookies "User" and "Birthday" and sets their value to "John Q. Public" and "02.01.1960". The durability of this cookies is respectable becouse their validity expires at the end of the century. (see "expires").


I've got a cookie from you.
Reading out cookies with tdbengine is very simple. A call of the CGIGetParam() function suffices to access all (accessible) cookies. Therefor just transfer to CGIGetParam() the text "cookie." then the name of the wanted cookie, for example cookie.Birthday.


...
VAR cUser : STRING = CGIGetParam("cookie.User")

CGIWriteLn('content-type: text/html')
CGIWriteLn('')
// untill here it was all HTTP-Header the following part is the HTML page.

CGIWriteLn('<html>')
CGIWriteLn('<head><title>cookie-test 2</title></head>')
CGIWriteLn('<body>Hallo '+cUser+'!<br> I know what you did last somer!</body>')
CGIWriteLn('</html>')
...


Eat the cookie!

Sometime it's possible that a cookie set before suddenly isn't of use anymore. For example: The user registers newly and gets a new session number. From user's view nothing militates against the dispose of this old cookie.
Therefor it'll the best thing if you set the date of expiry at one day in the past.
This can be done as allready described in the first line of a HTTP output.


...
CGIWriteLn('Set-Cookie: User=John Q. Public; expires=Monday, 01-Jan-2000 12:00:00 GMT;')
CGIWriteLn('content-type: text/html')
CGIWriteLn('')
// untill here it was all HTTP-Header the following part is the HTML page.

CGIWriteLn('<html>')
CGIWriteLn('<head><title>cookie-test</title></head>')
CGIWriteLn('<body>Cookie User deleted</body>')
CGIWriteLn('</html>')
...

The variable "User" in this cookie has no more validity so it won't be transfered to the server.

Continuative links:

http://wp.netscape.com/newsref/std/cookie_spec.html


Author: Thomas Friebel <tf@tdb.de>


tdbengine Anwendungen im Web:

Open-Source Web CMS


Open-Source Bug-Tracking


Free wiki hosting

Open-Source Wiki-System

Kostenloses Foren-Hosting

Diät mit tdbengine 8-)

tdbengine chat
irc.tdbengine.org
#tdbengine

   Copyright © 2003-2004 tdb Software Service GmbH
   Alle rechte vorbehalten. / All rights reserved
   Last changed: 20.12.2004
{Fehler für :execmacro{execmacro="sessionspy"}


ranking-charts.de

Programmers Heaven - Where programmers go!