Session debugging in CakePHP

Aug 09 2008

Often on IRC and the CakePHP google group, I hear people asking how to get values out of the Session or how to find out what is currently in the Session. Generally this is connected to AuthComponent, which is can be complicated component. However, some simple ‘crude’ PHP tactics can make the “whats’s in my session?” question very simple. Grab your layout file and add the following to it just above the <?php echo $cakeDebug; ?> statement.

Show Plain Text
  1.  
  2. <?php if (Configure::read('debug') > 1) :?>
  3.     <div id="cakeSession" class="cakeSession">
  4.         <h3>Session Info:</h3>
  5.         <?php pr($_SESSION); ?>
  6.     </div>
  7. <?php endif; ?>
  8.  

This simple bit of code should be pretty self evident. And makes it easy to check what’s going on your Session. I like only outputting it at debug > 1 so when I turn down to one both my SQL logs and Session dumps disappear.


Comments

Chris Pierce on 12/8/08

Mark,

something i do alot that is a little less “pretty” is

<pre>
<?php
   print_r($_SESSION);
?>
</pre>

Have Something to say?

*
* (Never published, I promise)
* You can use Textile markup, but be reasonable

Recent Artwork

  • CakePHP Test suite icons
  • Shuriken 2
  • Clumsy Penguins
  • Balloon Animals
  • Metal in the air! (vertical)
  • Cleavers