Welcome Guest, Not a member yet? Register   Sign In
Hooks not working iff im using @ob_start()
#3

(This post was last modified: 01-06-2020, 09:09 AM by shailesh tripathi.)

(01-05-2020, 06:28 AM)shailesh tripathi Wrote: Hooks to minimize and compress html code is working fine, if i am not using @ob_start(), but i need to use this function to remove several problems like  ** "PHP: Cannot modify header information", die() and exit() not working...** . Using @ob_start() makes useless  to minify and compress function.

I am using following code using Hooks file-
PHP Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function compress()
{
ini_set("pcre.recursion_limit", "16777");
$CI =& get_instance();
$buffer = $CI->output->get_output();

$re = '%# Collapse whitespace everywhere but in blacklisted elements.
        (?>            # Match all whitespans other than single space.
          [^\S ]\s*    # Either one [\t\r\n\f\v] and zero or more ws,
        | \s{2,}        # or two or more consecutive-any-whitespace.
        ) # Note: The remaining regex consumes no text at all...
        (?=            # Ensure we are not in a blacklist tag.
          [^<]*+        # Either zero or more non-"<" {normal*}
          (?:          # Begin {(special normal*)*} construct
            <          # or a < starting a non-blacklist tag.
            (?!/?(?:textarea|pre|script)\b)
            [^<]*+      # more non-"<" {normal*}
          )*+          # Finish "unrolling-the-loop"
          (?:          # Begin alternation group.
            <          # Either a blacklist start tag.
            (?>textarea|pre|script)\b
          | \z          # or end of file.
          )            # End alternation group.
        )  # If we made it here, we are not in a blacklist tag.
        %Six';

    $new_buffer = preg_replace($re, " ", $buffer);
$new_buffer =preg_replace('/<!--(.|\s)*?-->/', '', $new_buffer);

    // We are going to check if processing has working
if ($new_buffer === null)
{
$new_buffer = $buffer;
}

$CI->output->set_output($new_buffer);
$CI->output->_display();
}

/* End of file compress.php */
/* Location: ./system/application/hooks/compress.php */ 
And following code in my common file for handling requests...
PHP Code:
<?php
  
class Universal_Model extends CI_Model {

        public function __construct()
        {
                parent::__construct();
                ob_start(); //using it is best but hooks and compress not working with it, if not using it then several php functions not working like die(), exit()
        }


public function 
Sget_loginid(){
  if(isset($_SESSION['login_id'])){
   
    
return $_SESSION['login_id'];
  }
else return 
" Value is Null or empty..";
}

Everything is working fine, but using ob_start() ruins everything.... Im attaching screenshot of html output of the website pages with AND without using ob_start().        
Reply


Messages In This Thread
RE: Hooks not working iff im using @ob_start() - by shailesh tripathi - 01-06-2020, 07:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB