Session debugging in CakePHP

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. <?php if (Configure::read('debug') > 1) :?>
  2.     <div id="cakeSession" class="cakeSession">
  3.         <h3>Session Info:</h3>
  4.         <?php pr($_SESSION); ?>
  5.     </div>
  6. <?php endif; ?>

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

Mark,

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

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

anonymous user on 8/12/08

Use the session object to avoid issues where CakePHP stores sessions elsewhere.

$this->Session->read()

MrYellow on 6/8/09

Comments are not open at this time.