version | 1.0 |
released | 9 december 2004 |
author | ronald zötsch | feedback | ronald.zotsch (at) zutz.nl |
The custom PHP class clsCookie can be used to set cookies. With this class you can easily set multi-value cookies (with or without encryption), add and remove cookie-values or set and remove client cookies. This class can use Blowfish CBC encryption and MIME base64 encoding.
Installation of this class is as simple as "putting the files in your site-directory". Configuration parameters must be set in the config file which is included in the download-package. Your server (your own server or your ISP's server) must have the Mcrypt extension available in the host environment, ask your system administrator or ISP to install and activate the Mcrypt extension for your site. The classfile must be included in your PHP code and you can use the class in your code. Also read the rest of this documentation and examine the included example-file for extra information.
Only a free PHP5 version is available, this version is tested on a Windows 2000 SP4 server with IIS and PHP5 with the Zend engine and Mcrypt extension.
Mcrypt | http://mcrypt.sourceforge.net/ |
PHP5 | http://www.php.net/ |
Zend | http://www.zend.com/zend/download-php.php |
THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
$objCookieEncrypted = new clsCookie; | create a new cookieobject based on the class clsCookie |
$objCookieEncrypted->name = "encrypted"; | set the name of the cookie |
$objCookieEncrypted->expire = 86400; | set the cookie expiretime |
$objCookieEncrypted->setcryptkey("43@fga!gHT7"; | set the encryptionkey for the cookieobject |
$objCookieEncrypted->init(); | initialize the cookieobject, load cookievalues from client if the cookie exists |
$objCookieEncrypted->acookievalue = "a test cookievalue"; | assign a value to the cookieobject |
$objCookieEncrypted->send(); | send the cookieobject with the values to the client |
$objCookie = new clsCookie("noencryption"); | create a new cookieobject based on the class clsCookie. set the cookiename while creating the cookie object in memory |
$objCookie->nocrypt(); | disable encryption for the cookie object |
$objCookie->init(); | initialize the cookieobject, load cookievalues from client if the cookie exists |
$objCookie->destroy(); | clear the cookievalues in the cookie object in memory and remove the client cookie |
clsCookie->name | public read / change | string: name of the cookie |
clsCookie->expire | public read / change | integer: expiretime in seconds |
clsCookie->[cookieindex-valuename] | public read / change | string: a cookievalue |
clsCookie->[cookieindex-valuename] = [value] | assign a value to the cookie object |
clsCookie->setcryptkey(string: cryptkey); | set the cryptkey for the cookie object and enable encryption |
clsCookie->init(); | initialize the cookieobject (load client cookie into cookie object in memory) |
clsCookie->nocrypt(); | disable encryption for the cookie object |
clsCookie->send() | send the cookie object with all the values to the client |
clsCookie->destroy() | empty the values of the cookie object in memory and remove the client cookie |
clsCookie->remove(string: valuename) | remove a value from the cookie object and remove the value from the client cookie |
/* create a new cookie object */ $objCookie = new clsCookie; $objCookie->name = "nonencryptedcookie"; $objCookie->nocrypt(); $objCookie->init(); $objCookie->acookievalue = "this is a stored (non encrypted) cookie value"; $objCookie->asecondcookievalue = "this is a second stored (non encrypted) cookie value"; $objCookie->send(); |
create a cookie with non-encrypted values and send it to the client |
/* create a new cookie object */ $objCookieEncrypted = new clsCookie('encryptedcookie'); $objCookieEncrypted->setcryptkey("426#gFd!rq3"); $objCookieEncrypted->expire = 900; $objCookieEncrypted->init(); $objCookieEncrypted->acookievalue = "this is a stored and encrypted cookie value"; $objCookieEncrypted->asecondcookievalue = "this is a second stored and encrypted cookie value"; $objCookieEncrypted->athirdcookievalue = "this is a third stored and encrypted cookie value"; $objCookieEncrypted->send(); |
create a cookie with encrypted values and send it to the client |