[TYPO3] cookie fe_typo_user

bernd wilke xoonsji02 at sneakemail.com
Thu Apr 17 18:07:49 CEST 2008


on Thu, 17 Apr 2008 05:04:49 -0700, Korvo wrote:

> Hi, thks for your answer
> 
> where i must put $TSFE->fe_user->user['username']  ?? in a ts_lib class?

you just can read it anywhere in your extension PHP. 
It is written by the TYPO3 core.

example:
	if ($TSFE->fe_user->user['username']=='Korvo') {
		do_some_special_things_for_Korvo();
	}
 
> Do you know what i must do to create a new cookie name like for example
> Name: user_typo3
> (after maybe i can store username in his Content)
> 
> Fernandes
> 
go to http://de3.php.net/docs.php 
you may select a language you prefer.
then enter 'cookies' in the searchfield at top
you will find references to the php-function setcookie() and the global 
array $_COOKIE

this will do if you need the values in your extension (server-side).

if you need the info in the browser (client-side) you have to access the 
cookies by javascript. Writing is easy in the way:

function setCookie ( cookieName, cookieValue, cookieLifeTimeInSecs ) {
var now = new Date();
var cookieExpire = new Date(now.getTime() + cookieLifeTimeInSecs);
document.cookie = cookieName + "=" + cookieValue + ";"
                +" expires=" + cookieExpire.toGMTString() + ";";
}

this will ADD the cookie. other cookies are NOT removed!

reading a cookie with javascript is more complicated, because you can't 
access one cookievalue alone.
all cookies are stored in one single string, separated by ';' in the way:

'cookieName1=CookieValue1;cookieName2=CookieValue2;cookieName3=CookieValue3;'

you have to split the string like this:

cookieList = document.cookie.split(';');
for ( i = 0 ; i< cookieList.length ; i++ ) {
	c = cookieList[i].split('=');
	cookieArray[c[0]] = c[1];
}

now you have your cookie in cookieArray[cookieName]


bernd
-- 
http://www.pi-phi.de/t3v4/cheatsheet.html


More information about the TYPO3-english mailing list