[TYPO3] Cookie in extension
bernd wilke
xoonsji02 at sneakemail.com
Thu Apr 3 10:38:41 CEST 2008
on Wed, 02 Apr 2008 13:47:27 +0200, Jeppe Donslund wrote:
> Hi
>
> In an extension I would like to save a cookie when I change an
> select-box.
>
> I use onChage="" but how do I save the cookie so that I can access it on
> another page?
> I guess that it should be accessible in $GLOBALS["TSFE"] but I do not
> know how to do it.
>
I think setting is done by javascript:
function storecookie(name, value, expire) {
var now = new Date();
var expiretime = new Date(now.getTime() + expire);
document.cookie = name+"="+value+"; expires="+expiretime.toGMTString()
+";";
}
and request by PHP is done with:
$_COOKIES
request by javascript is a little bit more complicated because you only
get all cookies in one single string. You have to split it by ';' and '=':
cookiearray=document.cookie.split(';');
for (i=0;i<cookiearray.length;i++) {
tmp=cookiearray[i].split('=')
cookielist[tmp[0]]=tmp[1];
}
your cookie is in: cookielist['name']
bernd wilke
--
http://www.pi-phi.de/t3v4/cheatsheet.html
More information about the TYPO3-english
mailing list