title: Codeigniter - Hook to log GET / POST REQUESTS
body: <p>A client requires that all GET/POST requests are logged and stored for 90 days for their applicaiton. I have written a HOOK which seems to record some of the GETS / POSTS but there is less data than I would expect. For example, when submitting form data, the entries don't seem to be put in the log. Has anyone written something similar which works?</p>
  
  <p>Here is my version thus far:</p>
  
  <pre><code>class Logging {
  
      function __construct() {
          $this-&gt;CI =&amp; get_instance();
      }
  
      function index() {
          $this-&gt;CI-&gt;load-&gt;model('Logging_m');
          $this-&gt;CI-&gt;load-&gt;model('Portal_m');
  
          //get POST and GET values for LOGGING        
          $post = trim(print_r($this-&gt;CI-&gt;input-&gt;post(), TRUE));
          $get = trim(print_r($this-&gt;CI-&gt;input-&gt;get(), TRUE));
  
          $this-&gt;CI-&gt;Logging_m-&gt;logPageView(array(
                  'portal_id' =&gt; $this-&gt;CI-&gt;Portal_m-&gt;getPortalId(),
                  'user_id' =&gt; (!$this-&gt;CI-&gt;User_m-&gt;getUserId() ? NULL : $this-&gt;CI-&gt;User_m-&gt;getUserId()),
                  'domain' =&gt; $_SERVER["SERVER_NAME"],
                  'page' =&gt; $_SERVER["REQUEST_URI"],
                  'post' =&gt; $post,
                  'get' =&gt; $get,
                  'ip' =&gt; $this-&gt;CI-&gt;input-&gt;ip_address(),
                  'datetime' =&gt; date('Y-m-d H:i:s')
          ));
      }
  
  }
  </code></pre>
  
  <p>This data is stored in a model called 'Logging_m' which looks like this:</p>
  
  <pre><code>&lt;?php 
  class Logging_m extends CI_Model {
  
    function __construct() {
      parent::__construct();
    }
  
    function logPageView($data) {
      $this-&gt;db-&gt;insert('port_logging', $data);
    }
  
  }
  
  /* End of file logging_m.php */
  /* Location: ./application/models/logging_m.php */
  </code></pre>