Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I extend the session class by creating <code>/application/libaries/MY_Session.php</code></p> <p> <pre><code>class MY_Session extends CI_Session { function __construct() { parent::__construct(); $this-&gt;tracker(); } function tracker() { $this-&gt;CI-&gt;load-&gt;helper('url'); $tracker =&amp; $this-&gt;userdata('_tracker'); if( !IS_AJAX ) { $tracker[] = array( 'uri' =&gt; $this-&gt;CI-&gt;uri-&gt;uri_string(), 'ruri' =&gt; $this-&gt;CI-&gt;uri-&gt;ruri_string(), 'timestamp' =&gt; time() ); } $this-&gt;set_userdata( '_tracker', $tracker ); } function last_page( $offset = 0, $key = 'uri' ) { if( !( $history = $this-&gt;userdata('_tracker') ) ) { return $this-&gt;config-&gt;item('base_url'); } $history = array_reverse($history); if( isset( $history[$offset][$key] ) ) { return $history[$offset][$key]; } else { return $this-&gt;config-&gt;item('base_url'); } } } </code></pre> <p>And then to retrieve the URL of the last page visited you call</p> <pre><code>$this-&gt;session-&gt;last_page(); </code></pre> <p>And you can increase the offset and type of information returned etc too</p> <pre><code>$this-&gt;session-&gt;last_page(1); // page before last $this-&gt;session-&gt;last_page(2); // 3 pages ago </code></pre> <p>The function doesn't add pages called using Ajax to the tracker but you can easily remove the <code>if( !IS_AJAX )</code> bit to make it do so.</p> <p>Edit: If you run to the error Undefined constant IS_AJAX, assumed IS_AJAX add the line below to <code>/application/config/constants.php</code></p> <pre><code>define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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