Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use a post controller <a href="http://ellislab.com/codeigniter/user-guide/general/hooks.html" rel="nofollow">hook</a>.</p> <ul> <li>Enable hooks in <strong>application/config/config.php</strong>.</li> <li><p>Then in <strong>application/config/hooks.php</strong>;</p> <pre><code>$hook['post_controller'] = array( 'class' =&gt; 'PostController', 'function' =&gt; 'log_it', 'filename' =&gt; 'PostController.php', 'filepath' =&gt; 'hooks', 'params' =&gt; array() ); </code></pre> <hr></li> <li><p>Create a file in <strong>application/hooks/PostController.php</strong></p> <pre><code>&lt;?php class PostController { private $ci; private $filepath; public function __construct() { $this-&gt;ci =&amp; get_instance(); $log_path = ($this-&gt;ci-&gt;config-&gt;item('log_path') != '') ? $this-&gt;ci-&gt;config-&gt;item('log_path') : APPPATH.'logs/'; $this-&gt;filepath = $log_path.'action_log'; } public function log_it($log_message=NULL) { if ($log_message == NULL) { $log_message = date('d/m/Y H:i:s')."::"; $log_message .= $this-&gt;ci-&gt;session-&gt;userdata('username')."::"; $log_message .= $this-&gt;ci-&gt;input-&gt;ip_address()."::"; $log_message .= $this-&gt;get_client_ip()."::"; $log_message .= $this-&gt;ci-&gt;router-&gt;class."::"; $log_message .= $this-&gt;ci-&gt;router-&gt;method."::"; $log_message .= uri_string()."::"; if (isset($_POST)) { foreach ($_POST as $key =&gt; $value) { $log_message .= "[$key] =&gt; $value;"; } } $log_message .= "\r\n"; } $fp = fopen($this-&gt;filepath, FOPEN_WRITE_CREATE); fwrite($fp, $log_message); fclose($fp); } private function get_client_ip() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { //check ip from share internet $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //to check ip is pass from proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } } ?&gt; </code></pre></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload