CodeIgniter - Editing Output Buffer Before Sent To Browser?

May 5, 2011

I'm researching the PHP framework CodeIgniter. I need some help regarding editing the output before it's flushed to the user. Usually in PHP, you can just use ob_start(); and then ob_get_clean(); to retrieve the contents. While reading the CodeIgniter documentation, though, they say all output is already buffered.

Has anybody experience with unintentionally starting a second ob_start() ? Alternatively, can anyone talk about the CodeIgniter output buffering so I may edit it?

View 1 Replies


Putting The Output From The Second Ob_start() In The First Output Buffer

The following is not achieving what I desire

echo ob_start() . "<br>";
echo "1x<br>";
echo ob_start() . "<br>";
echo "2x<br>";
echo ob_flush() . "<br>";
echo "3x<br>";
echo ob_flush() . "<br>";

The output is the following


I assume the problem is its putting the output from the second ob_start() in the first output buffer. But how do I get my desired output? Edit: Basically what I am trying to achieve is providing the tag which needs to be in the head of a HTML document at a latter point in the output. Ie, half way through the script after it has already printed the docs head infomation it needs to then provide the.

View 4 Replies

How To Buffer Output

vishal here. can anyone tell me that how to buffer output and then send
the output to client at a time.

what is my problem is that i have a php file which runs query on
database and takes some time to get query result. so what i want is i
want to buffer output till the query returns result and then send the
buffered output to client at a time.

View 2 Replies

Output Buffer

Not that I take a look at the output buffer functions do you think its possible to use to gather results from JavaScript? For example, JavaScript feeds the variables like so:

<!FeedPHP-KeyName JavaScriptVarOrResult EndFeed>

and then use the output buffer to wait for the page to load before using preg_replace() or something to get the results of the PHP feeds? If you can, how would you suggest going about it?

View 6 Replies

Output Buffer Not Working?

I am trying to get some basic output buffering to work and not sure why it isn't...

echo "Line #1...<br>";

View 3 Replies

Output Buffer And Memory Issue

I got a strange problem: Using php 4.4.x, I capture the whole output for a webpage into the output-buffer by using ob_start and ob_get_clean, because I got to make some replacements in the html-code before sending the page to the browser.

This worked fine with a small page, but now I got a page for which the html-code is about 280 KB (not too big I think). But I get an server-error 500 for this script on my linux-based webhoster....

View 3 Replies

Errors Inside Of Output Buffer?

'm having some problems with the output buffer. I am buffering my script and printing the result using a callback. The problem is that if a error is thrown at any point, nothing is being shown and I am getting a blank screen. I have tried setting my own custom error handlers but nothing seems to work. I have a feeling this is because the errors are causing my buffer to call the callback method instead of my error handler.Either that or it's because I have the error handler as a static method, but changing that causes issues elsewhere.

public function constructor()
ob_start(array(__CLASS__, 'render'));

View 2 Replies

Caching The Output Buffer Of Pages?

I've been caching the output buffer of pages lately, but now I want to cache the values of variables.I have a PHP file that does a bunch of MySQL queries, then fills variables with various data from those queries.Some of those variables will never change but some will change quite often. How can I cache certain variables in this manner? I'm using file-based caching

View 5 Replies

Output Buffer While Page Loading?

I have a script which is like a bot, it is running through the database checking about 8000 links to see of the link still exists, if the page had redirected (301, 302, 303) or if the site is down.I just executed the script and monitored the Database it is writing to.Sweet the DB contains all the records I asked it to (set a limit of 1000)But the page never loaded.As it loops through each record, it checks the record and writes to the DB and the screen.HOw do I show this on the screen as soon as i echo that point, instead of waiting till the end of the script.

View 6 Replies

Clean The Output Buffer When Script Crashes?

I use register_shutdown_function() to let PHP call a function at any time my script crashes. After I've logged that to a file, I want to display a beautiful error-message to the user.To do that, I want to clean the current output buffer. I think there's a stack of output buffers (not sure), so the big question is if I could simply call ob_end_clean() in my shutdown-callback function and then print out my error page?

At least, on my MAMP environment on the mac (local) I can echo out something in my callback function, even though in the documentation some people claim that this is impossible. But if that works, I must be sure that anything that went previously to the output buffer really gets cleaned. On the other hand, the next question would be what happens with sent headers?

View 1 Replies

Stop Output Buffer From Going Over The Memory Limit?

Most of my PHP apps have an ob_start at the beginning, runs through all the code, and then outputs the content, sometimes with some modifications, after everything is done.

//Business Logic, etc
echo apply_post_filter(ob_get_clean());

This ensures that PHP errors get displayed within the content part of the website, and that errors don't interfere with header and session_* calls.My only problem is that with some large pages PHP runs out of memory. How do I stop this from happening?

Write all of the buffered content to a temporary file and output that.When the buffers reaches a certain size, output it. Although this might interfere with the post filter.Raise the memory limit (thanx @troelskn).Whats the drawbacks on each of these approaches? Especially raising the memory limit?

View 4 Replies

Security - What Are The Vulnerabilities Of Output Buffer Functions

What are the vulnerabilities of output buffer functions in PHP? Not saying it has vulnerabilities, merely wondering if there were any Why is it considered ugly php code? [URL]

View 2 Replies

Header Location Gets Sent Even Inside An Output Buffer?

I am having trouble suppressing a PHP Location Header from inside an output buffer. It is my understanding that output buffers should suppress headers until they are flushed. I also thought that no headers should be sent with ob_end_clean(). However if you see the code below, if I uncomment the header line (second line) I always get redirected to google and never see 'finished'.

$output = ob_get_contents();
$headers_sent = headers_sent();
$headers_list = headers_list();

I need to suppress any header redirects, ideally catching them in the output buffer so I know those conditions will produce a redirect. I know I can do this with curl (setting follow redirects to false), but as all the files I want to buffer are on my own server curl is proving very slow and tying up loads of db connections.

View 3 Replies

Compress Huge Page With Output Buffer?

I've got a page with roughly 500KBs of data, Basically I need it all on one page.I've tried adding 'ob_start('compress')' and 'ob_end_flush();' but it gives me an error at the end and i'm not sure if this is the best way.Would adding ob_start('gzcompress') work well? Would I need to add a flush at the bottom?

View 3 Replies

Flush The Zend Output Buffer At The Controller Stage?

I have a Zend Controller that serves files to users I have used Noginn SendFile action helper to do the actual streaming of the file, but the code simply uses readfile($path) to place the content of the file into the buffer after setting the MIME and content type etc

The problem is that the file that arrives down the pipe has an extra blank byte 0x20 at the beginning, not a train smash for text files but obviously fatal for images My controller has the following code in it to stop any view scripts from being rendered:


but I think a whitespace is still getting placed in the output buffer somewhere before the file is getting streamed. Is there a way to clear the output buffer before I stream the file?

View 1 Replies

Output Buffer Benchmark (microtime Inaccurate When Used With Usleep?)

I post a strange behavior that could be reproduced (at least on apache2+php5).I don't know if I am doing wrong but let me explain what I try to achieve.I need to send chunks of binary data (let's say 30) and analyze the average Kbit/s at the end :

I sum each chunk output time, each chunk size, and perform my Kbit/s calculation at the end.

Code: [Select]<?php

// build my binary chunk
$var= '';


Does the buffer output is not synchronous ?

View 10 Replies

Php5 - Output Buffer Benchmark Microtime Inaccurate When Used With Usleep?

I post a strange behavior that could be reproduced (at least on apache2+php5).I don't know if I am doing wrong but let me explain what I try to achieve.I need to send chunks of binary data (let's say 30) and analyze the average Kbit/s at the end :I sum each chunk output time, each chunk size, and perform my Kbit/s calculation at the end.

// build my binary chunk
$var= '';

View 1 Replies

Header Redirect Not Working When Posting A Form - Using Output Buffer - But Does In Other Cases?

I have an unusual problem, only happening on one server. Following code

elseif ($_GET['action']=='login') {
if (empty($_POST['login_name'])) { $_POST['login_name']=''; }
if (empty($_POST['login_pass'])) { $_POST['login_pass']=''; }
if (!empty($_POST['send'])) {
if (($_POST['login_name']==_ADMIN_NAME) and ($_POST['login_pass']==_ADMIN_PASS)) {
//Successfully logged in
// DOES NOT WORK............

So the problem is this if i click the link logout, all goes well and i get redirected to $filename.
If i submit the login form it checks if the post is correct, set's the session var, but then dies instead of redirecting.

I got output buffers on, all error reporting but (no errors), it doesn't redirect when I post with the form even though it definitely passes (because the session var is set and I get to the die part)

View 8 Replies

Performance - How Does The Output Buffer Work (using $_SERVER['REQUEST_TIME'] To Calculate Script Execution Time)

i really didnt know how to word the title so i did the best i could. we have an issue where we calculate final script (web based) execution time. we do a simple


we find that sometimes the script is shown to take longer then X seconds to execute. we are 100% sure this is not an issue with mysql, memcached, sphinx or any of the other usual culprits. please... just assume that its not 'something on our end' holding it up.

we even added this simple exec time check way way up in the script, before any heavy processing is done and there are still some hits. mainly far far away overseas clients. so i am thinking this must be related to the output buffer somehow. so the question is as follows: in php + apache, how does the output buffer work? lets say you have the following:............

View 2 Replies

Explore The Html Editing Capabilities Of Browser - Clean Html Regex

I always have many dificulties with regex or regular expressions, I'm trying to explore the html editing capabilities of browser, but most times I got things I don't need, like this one

<div style="text-align: left;"><span style="font-size: small;"><font face="verdana"><br></font></span></div>

Can someone be so nice to provide me a regex to transform this into just <br>? possible to have one dealing with diferent combinations like font face could be other than verdana and the style for text-align could be center per example.

View 2 Replies

Avoid Browser Cache Using Codeigniter?

Facing issue related to browser chache.

function doUpload(){
$data['includeView'] = "profileconfirm";
$config['upload_path'] = './img/images/uploaded/';


this method is used for image upload. After successful image upload, it loads index view page, which internally includes profileconfirm view page. But on profileconfirm page new uploaded image is not going to reflect. Some times it works fine, but some times not, this is happen most of the times.

View 2 Replies

How CodeIgniter Keeps Session Data Even When Browser Closes

I wonder how does the session work in CodeIgniter. Isn't the session suppose to be automatically destried when the browser is closed? The CodeIgniter does not destroy the session on browser close by default:

$config['sess_expire_on_close'] = FALSE;

Instead we can set the session expire time: $config['sess_expiration'] = 7200;

Now for example if I set the expiration time to 0, it will keep the session as long as I do not destroy by myself: $this->session->sess_destroy(); So how does the CodeIgniter keeps the session information for specific time, even after the browser is closed? Also, is it secure if use this default setting(of not expiring the session with browser close) to keep user login for few days? (eg. store in session 'logged_in' => TRUE )

View 1 Replies

Output It To Web Page On CodeIgniter?

I made a PHP-function which returns an array and then I move its value to a variable $a. How can I output it to a web page on CodeIgniter?

View 5 Replies

CodeIgniter Output XML In View?

I tried to output XML in the view file. The view file is result_view.php and its first line is

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

But I get the error "Content is not allowed in prolog". So how to do this correctly? I use Eclipse + PDT.

View 3 Replies

No Output To The Browser

I'm trying to build a message board in PHP/MySQL, and for some strange reason, there is no output sent to the browser after the second of my two include() statements. Code:

View 6 Replies

Telling The Browser To Open Or Download A File In Codeigniter?

In Codeigniter, we can use the force_download($file_name,$data) function from the download helper to force the browser to download a file.

But this is not what I need, I would like Codeigniter to respond a http header with the MIME type that the file corresponds to, so that the browser may or may not download the file, depending on whether there is an application registered for that MIME type on the client machine (if there is one, that application will open that file).

Is there a way of doing this with Codeigniter?

View 1 Replies

Copyrights 2005-15, All rights reserved