[TYPO3] Cookie in extension

Jeppe Donslund jd at webmasters.dk
Thu Apr 3 11:20:52 CEST 2008


Hi Bernd.

My problem is not to create and save the cookie, but when I reload the 
page, the doesn't exist anymore.

I kan create in in some php code. Then I kan print it within the same 
php-document. But when I return to the Typo3 output. The cookie doesn't 
exist anymore.

Regards
Jeppe D.


bernd wilke skrev:
> 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


More information about the TYPO3-english mailing list