Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 4 revisions

Modify the Output class' function _write_cache() to prevent your flashdata from getting stuck in a cache file. Save as system/application/libraries/MY_Output.php.

Lines added: [code] // Na-ah-ah! no flashing allowed in the cache; $userdata = $CI->session->all_userdata(); foreach ($userdata as $k => $v) { if (strpos($k,'flash:') !== FALSE) return; } [/code]

[size=4]MY_Output[/size] [code] <?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**

  • A better output Class

  • Responsible for sending final output to browser

  • @package CodeIgniter

  • @subpackage Libraries

  • @hacked-by Bradford Mar */ class MY_Output extends CI_Output {

    /**

    • Write a Cache File
    • @access public
    • @return void */
      function _write_cache($output) { $CI =& get_instance();

    // Na-ah-ah! no flashing allowed in the cache; $userdata = $CI->session->all_userdata(); foreach ($userdata as $k => $v) { if (strpos($k,'flash:') !== FALSE) return; }

     $path = $CI->config->item('cache_path');
    
     $cache_path = ($path == '') ? BASEPATH.'cache/' : $path;
     
     if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
     {
         return;
     }
     
     $uri =    $CI->config->item('base_url').
             $CI->config->item('index_page').
             $CI->uri->uri_string();
     
     $cache_path .= md5($uri);
    
     if ( ! $fp = @fopen&#40;$cache_path, 'wb'&#41;)
     {
         log_message('error', "Unable to write cache file: ".$cache_path);
         return;
     }
     
     $expire = time() + ($this->cache_expiration * 60);
     
     flock($fp, LOCK_EX);
     fwrite($fp, $expire.'TS---&gt;'.$output);
     flock($fp, LOCK_UN);
     fclose($fp);
     @chmod($cache_path, DIR_WRITE_MODE);
    
     log_message('debug', "Cache file written: ".$cache_path);
    

    } } [/code]

Clone this wiki locally