Hey Anja, Thanks for sharing. For the session data parsing you might wanne check this page out: http://www.mail-archive.com/[email protected]/msg40110.html
This certainly has the possibility to become a great bakery article :). Cees-Jan On Jan 7, 2:00 pm, "Liebermann, Anja Carolin" <[email protected]> wrote: > Hi everybody, > > Someone asked for a solution to show who is online 1-2 weeks ago. I just > solved it for me and thought I share it with you: > > 1. change session handling from whatever to 'database' > following:http://book.cakephp.org/view/44/CakePHP-Core-Configuration-Variables > 2. Login and check if your database table is populated. > 3. write a function to get the data. I placed it in the users-controller > since it is about user information: > > function whoisonline(){ > > $sessiondata = $this->User->query('SELECT `data` FROM > `cake_sessions`'); > //pr($sessiondata); > foreach($sessiondata as $sess){ > $sessdata = > preg_replace('/[0-9]{1,3}:/','',$sess['cake_sessions']['data']); > $sessarray = explode(';s:',$sessdata); > > //pr($sessarray); > > foreach ($sessarray as $key =>$wert){ > if ($wert == '"name"') { > break; > } > } > $key++; > $name = $sessarray[$key]; > > $name = preg_replace('/"/','',$name); > $onlineusers[]=$name; > } > //pr($onlineuser); > $this->set('onlineusers',$onlineusers); > return $onlineusers; > } > > The 'pr's are for debugging, you can uncomment them and see what values > you get. This function gets the session data and extracts the username > from it. > > 4. Create an element /views/elements/whoisonline.ctp to fetch the data: > > <?php > $onlineusers = $this->requestAction('users/whoisonline/'); > $everybodyhere = implode(', ',$onlineusers); > echo $everybodyhere; > ?> > > 5. Include your element with the proper caching parameter into your > layout template. E.g.: > > <div id="footer"> Who is online: <? > echo $this->renderElement('whoisonline', array('cache' => array('time'=> > "+5 minutes",'key'=>'unique value'))); > ?></div> > > At the moment it looks ok. I will test it now over some time. > > Anja --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
