CookieManager
Since the 1.9 branch the
CookieManager is available. This component enables you -
similar to the
SessionManager - to sophistically manage cookies. Due to the fact, that the
implementation of HTTP cookies does not provide namespace support, the component was extended to
support this feature. Now cookie values can be stored within different namespaces.
The following box describes examples for the
CookieManager usage:
PHP-Code
// include the CookieManager
import('tools::cookie','CookieManager');
// create the CookieManager and apply the desired namespace
$cM = new CookieManager('my::namespace');
// try to get the cookie value
$value = $cM->readCookie('key');
if($value !== null){
echo '
Cookie value: '.$value;
}
else{
$cM->createCookie('key','value');
echo '
Setting cookie...';
}
// delete cookie if dedired
if(/* ... */){
$cM->deleteCookie('key');
}
// update cookie if desired
if(/* .. */){
$cM->updateCookie('key','value_2');
}
// change namespace of the current instance
$cM->setNamespace('my::second::namespace');
In the examples above, the cookie domain and path is gathered automatically. If desired, the
domain and path can be set to different values, using the futher arguments of the available methods.
Details can be taken from the API documentation.
Note: Please be aware, that the cookie handling only works with domains unlike
localhost. For development purposes ist is recommended to create a seperate VHOST.
Comments
Do you want to add a comment to the article above, or do you want to post additional hints? So please click
here. Comments already posted can be found below.
There are no comments belonging to this article.