Hooks not working iff im using @ob_start() - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Hooks not working iff im using @ob_start() (/showthread.php?tid=75177) |
Hooks not working iff im using @ob_start() - shailesh tripathi - 01-05-2020 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. RE: Hooks not working iff im using @ob_start() - jreklund - 01-05-2020 Could you provide us with an example code? Why are you bothering with compressing HTML? With modern internet you will not find it worth your while, as long as you have gzip enabled on your server for HTML. Have you placed exit; after all your redirect(); functions? That's the only way to get rid of "Cannot modify header information"*. If it's not your redirect() functions creating problems, you may have whitespace in your files. UTF-8 BOM etc in your files. https://stackoverflow.com/a/8028987 * The easy way at least, as you need to stop it rendering HTML or other content that sends headers. RE: Hooks not working iff im using @ob_start() - shailesh tripathi - 01-06-2020 (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'); PHP Code: <?php RE: Hooks not working iff im using @ob_start() - shailesh tripathi - 01-06-2020 (01-05-2020, 11:30 PM)jreklund Wrote: Could you provide us with an example code?Im using that code to remove comments and whitespaces & other stuff to reduce html rendered page code upto few lines. Code is working fine without any problem. Using ob_start() function makes is uneffective. I have updated the question by providing sample code . RE: Hooks not working iff im using @ob_start() - InsiteFX - 01-06-2020 IF you look at your code you are loading the title twice and also jQuery twice. I suggest that you go to w3schools and catch up on html. RE: Hooks not working iff im using @ob_start() - shailesh tripathi - 01-06-2020 (01-06-2020, 08:47 AM)InsiteFX Wrote: IF you look at your code you are loading the title twice and also jQuery twice.That's not the matter sir, instead of pointing out unusual mistakes, could you please help on actual problem if you can. RE: Hooks not working iff im using @ob_start() - InsiteFX - 01-07-2020 Well it's a proven fact that any kind of errors can cause multiple other errors. So you start by fixing your current errors that you know about then proceed with the other errors. And your ob_start should be place above the class under the <php RE: Hooks not working iff im using @ob_start() - jreklund - 01-08-2020 It may be that you never flush it as CodeIgniter already buffers it's output. So you are getting double buffering. https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Loader.php#L947 But my recommendation are that you ignore this minify and enable gzip compression instead. https://github.com/bcit-ci/CodeIgniter/blob/develop/application/config/config.php#L420 If you aren't doing it on server level. (This is the recommended way!) If you still want it to work, with that slow preg_replace function. You need to fix your redirect(); and add a working exit; as they do work. If applied correctly. Do you have an example that dosen't work? You aren't using a caching server I guess? That mean you will be running that replace every time a user visit that page. RE: Hooks not working iff im using @ob_start() - shailesh tripathi - 01-08-2020 (01-08-2020, 11:56 AM)jreklund Wrote: It may be that you never flush it as CodeIgniter already buffers it's output. So you are getting double buffering.You are right as because Buffering by Codeigniter is probably the reason behind it. Thanks for this suggestion, I should use gzip compression. "That mean you will be running that replace every time a user visit that page." ---> Yes "Do you have an example that doesn't work?" ---> I will share the code where i am getting the problem on exit() and die() when im not using ob_start() as soon as possible. RE: Hooks not working iff im using @ob_start() - shailesh tripathi - 01-10-2020 (01-07-2020, 09:21 AM)InsiteFX Wrote: Well it's a proven fact that any kind of errors can cause multiple other errors.Thanks, i have done that correction in code that you had suggested previously . I have changed the position of the ob_start to Under php tag, but still facing that problem. |