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?

ADVERTISEMENT

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

Jun 15, 2009

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

[Code]....

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 View Related

How To Buffer Output

Jul 17, 2005

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 View Related

Output Buffer

Dec 24, 2005

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 View Related

Output Buffer Not Working?

May 23, 2011

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

Code:
<?php
echo "Line #1...<br>";
flush();
sleep(2);
[code]...

View 3 Replies View Related

Output Buffer And Memory Issue

Oct 24, 2007

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 View Related

Errors Inside Of Output Buffer?

Sep 8, 2009

'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'));
[code]....

View 2 Replies View Related

Caching The Output Buffer Of Pages?

Apr 14, 2011

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 View Related

Output Buffer While Page Loading?

Feb 2, 2010

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 View Related

Clean The Output Buffer When Script Crashes?

Dec 27, 2009

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 View Related

Stop Output Buffer From Going Over The Memory Limit?

Nov 11, 2008

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.

ob_start()
//Business Logic, etc
header->output();
echo apply_post_filter(ob_get_clean());
footer->output();

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 View Related

Security - What Are The Vulnerabilities Of Output Buffer Functions

Mar 28, 2011

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 View Related

Header Location Gets Sent Even Inside An Output Buffer?

May 25, 2011

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'.

ob_start();
//header("Location: http://www.google.com");
$output = ob_get_contents();
ob_end_clean();
$headers_sent = headers_sent();
$headers_list = headers_list();
[Code]...

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 View Related

Compress Huge Page With Output Buffer?

Dec 14, 2009

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 View Related

Flush The Zend Output Buffer At The Controller Stage?

Jun 4, 2010

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:

$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();

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 View Related

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

Apr 20, 2011

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= '';

[code]...

Does the buffer output is not synchronous ?

View 10 Replies View Related

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

Apr 20, 2011

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.

<?php
// build my binary chunk
$var= '';
$o=10000;
[code].......

View 1 Replies View Related

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

Apr 28, 2009

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
$_SESSION['logged']=1;
// 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 View Related

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

Jul 7, 2011

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

if(time()-$_SERVER['REQUEST_TIME']>X){
logMe();
}

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 View Related

Explore The Html Editing Capabilities Of Browser - Clean Html Regex

Jun 10, 2011

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 View Related

Avoid Browser Cache Using Codeigniter?

Jan 24, 2011

Facing issue related to browser chache.

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

[code]....

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 View Related

How CodeIgniter Keeps Session Data Even When Browser Closes

Jul 15, 2011

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 View Related

Output It To Web Page On CodeIgniter?

Mar 8, 2010

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 View Related

CodeIgniter Output XML In View?

May 21, 2010

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 View Related

No Output To The Browser

Jul 10, 2006

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 View Related

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

Feb 15, 2011

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 View Related

CodeIgniter Pretty Debugging Output

Mar 16, 2011

Basically what I want to do is be able to set a switch somewhere: $debugging_mode = 0 or 1 that will allow me to attach a nicely formatted output to the bottom of my views. I have written a library with a lot going on and I have some output like this:

[CODE....]

My question is what is the cleanest way to get pretty debugging output? ( I am aware of CI's profiler, but I still need something extra). Where is a good place to set a global debugging mode? I know zend framework has a development or production setting in the .htaccess file, but I don't see that in CI . Should I use PHP's native output buffer to collect my debugging stuff? then how could I append that to the view?

View 1 Replies View Related

How Does CodeIgniter Output Caching Work

Jul 5, 2010

I read this link :- [URL] It is written that :- When a page is loaded for the first time, the cache file will be written to your system/cache folder and that we can cache a view by $this->output->cache(60);. But how does it actually work? What if regularly my users keep updating and deleting records as a result of which view changes very often.

Will it show the modified data? or will the cache bring back the old stale data? (before inserts and updates)? If it automatically manages and brings fresh data from the database, then what is purpose of specifying the minutes in cache function?

View 2 Replies View Related

Return Full Output From Function In CodeIgniter?

Apr 8, 2011

I need to output all books from all shelfs. This code bellow only outputs last shelf of books.My Controller:

function index()
{
$data['books'] = $this->_books();

[code]...

View 2 Replies View Related

Including File And Output To Browser

Jul 30, 2005

I am not sure I understand the rules as to what exactly gets output to a
browser and when. If I include a text only file or an html file, these will
show up in the browser regardless of where in the script they are included.

View 2 Replies View Related

Preventing Function Output Going To Browser

Jul 17, 2005

How do I prevent the output of a user defined function from going to the
browser?

In my script I do something like:

$MyVar = MyFunction($var1,$var);

which works, except that the output from MyFunction is sent to the
browser. I simply want it to set in the variable.

View 1 Replies View Related

Browser Output Cutting Short In IE

Jun 26, 2006

I wish I knew if this was even a PHP problem or not! It's probably
Internet Explorer but here goes anyway...
Random pages at random times don't appear correctly in IE6, the HTML is
actually cut short at seemingly random points (it's very random, you
know). It could be at any character on any line. This is usually
displayed simply as a background with no content, but viewing the
source actually shows quite a lot, although sometimes it won't let me
see it at all!
I've tried messing about with cache control and output buffering but
nothing makes a difference.
I have another site built on very similar code but someone else has had
their grubby paws on this one so I'm not sure what might have been done
to it. :o(

View 7 Replies View Related

Query Output Does Not Print On The Browser?

Jul 4, 2011

I am writing a simple user/login system in Php with postgresql.

I have a function that confirms whether username/passwords exists, which gets activated when a user presses the Login button.

public function confirmUserPass($username, $password){
$username=pg_escape_string($username);
/* Verify that user is in database */
$q = "SELECT password FROM users WHERE email = '$username'";
$result = pg_query($this->link,$q);
/* Do more operations */
}

I want to print the query stored in $results such that I can see it on the browser. When I do it in phppgAdmin using SQL it shows me the output but I cannot see it on the browser. I tried echo and printf but I could not see anything on the browser. I also tried to see view source from the browser but it shows nothing.

View 2 Replies View Related

Streaming Output To A File And The Browser?

Mar 6, 2009

I'm looking for something more efficient than this:

<?php
ob_start();
include 'test.php';

[code]...

View 3 Replies View Related

Output Image(chart) To Browser?

Oct 22, 2010

I'm currently trying to output an image (chart generated with PHP).After I get all the data I need I just output the image to disk with:

imagepng($img, "img/graf.png", 0);
imagedestroy($img);

Then I call the image on the page, but the browser uses always the cached image instead of the newly generated image.So I am trying to output the image to browser.Main page is k_b.php.The graph is generated, when I call the file grafico.php with an

include 'grafico.php';
present in k_b.php file.

Then I have some code that shows diferent buttons/text depending on other factors, but I must show that chart.When I try to output the chart directly to the browser I just shows the chart and nothing else. with imagepng($img)

View 2 Replies View Related

Output File On Disk To Browser?

Jan 8, 2010

i want to serve an existing file to the browser in php.i've seen examples about imagejpeg but that function seems to save a file to disk and you have to create a right sized image object first.in asp.net i do it by reading the file in a byte array and the call context.Response.BinaryWrite(bytearray), so i'm looking for something similar in php.

View 4 Replies View Related

Output Shown Only In Command Line And Not In Browser

Jun 29, 2006

I have the following code in a script
--------------------------------------------------------------------------------------------------------------------------------
foreach($serverlist as $sno=>$serverdata) {
$servername = $serverdata['name'];
if($servername) {

unset($outputstr, $outputarr);
$outputstr = exec("ssh -n ".$servername." 'fstat | wc -l'",
$outputarr);

echo
"
----------------------------------------------------------";
echo "
ssh -n ".$servername." 'fstat | wc -l' ";
echo "
servername = ".$servername;
echo "
outputstr = "; var_dump($outputstr);
echo "
outputarr = "; var_dump($outputarr);

}
}
--------------------------------------------------------------------------------------------------------------------------------

When executed from browser it displayed:

---------------------------------------------------------- ssh -n
192.168.0.155 'fstat | wc -l' servername = 192.168.0.155 outputstr =
string(0) "" outputarr = array(0) { }
---------------------------------------------------------- ssh -n
192.168.0.156 'fstat | wc -l' servername = 192.168.0.156 outputstr =
string(0) "" outputarr = array(0) { }
---------------------------------------------------------- ssh -n
192.168.0.159 'fstat | wc -l' servername = 192.168.0.159 outputstr =
string(0) "" outputarr = array(0) { }

--------------------------------------------------------------------------------------------------------------------------------

When executed from command line it displayed:

PHP Warning: Module 'ctype' already loaded in Unknown on line 0
PHP Warning: Module 'SimpleXML' already loaded in Unknown on line 0
PHP Warning: Module 'dom' already loaded in Unknown on line 0
PHP Warning: Module 'iconv' already loaded in Unknown on line 0
PHP Warning: Module 'pspell' already loaded in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/20041030-debug/ssh2.so' -
/usr/local/lib/php/20041030-debug/ssh2.so: unsupported file layout in
Unknown on line 0
PHP Warning: Module 'pcre' already loaded in Unknown on line 0
PHP Warning: Module 'xml' already loaded in Unknown on line 0
bash: fstat: command not found
Password:

View 1 Replies View Related

Cannot Output To Browser But Can On Shell (Apache Segfault 11)

Jul 17, 2005

When I run my script via the shell (e.g. "php test.php") the script
generates the correct output everytime. If I attempt to access the
script via the web (e.g. http://localhost/test.php), Apache reports a
segfault:
- [notice] child pid 11005 exit signal Segmentation fault (11)

Occasionally, the script will create vaild output to the browser (but
this is rare). If I stop the httpd service and run "httpd -X", the
script works flawlessly and Apache reports no errors.

PHP is working correctly -- simpler php applications and phpinfo(); can
generate valid output using the httpd service.

I am running:
- Linux Fedora Core 3 (2.6.11-1.14_FC3)
- Apache (Apache/2.0.52 (Fedora)) rebuilt RPM with oci8
(instantclient support)
- PHP (4.3.11)
- PEAR::DB (1.7.5)
- Smarty PHP Template engine (2.6.9)

View 1 Replies View Related

Zend_Session: Session Must Be Started Before Any Output Has Been Sent To The Browser

Oct 13, 2010

I've run into this issue before, but I can't remember how to solve it. I have created a bare bones (can't get any simpler) controller, and am just trying to echo something to the browser, and I am getting this message:

Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser ...

Here's my entire controller. It's displaying 'success', but it also displays the error message. How can I silence that error message so I can simply echo something to the browser?

<?php
class CacheController extends Zend_Controller_Action
{
public function clearAction()
{
$this->_helper->layout->disableLayout();

[Code].....

View 4 Replies View Related

Output Resized Animated Gif To Browser Using Imagick?

Jun 12, 2010

I intent to resize an animated gif and outputing it to the browser on-the-fly. My problem is that when I save the resized image it is of good quality, but if I echo it to the browser it is of poor quality and the animation is removed. Here is the code:`

header("Content-type:image/gif");
try
{
[code]....

View 1 Replies View Related

Output To The Browser All Numbers Greater Than 4 Digits?

Apr 20, 2011

$x="On February 13, 2009, at exactly 23:31:30 (UTC) the decimal representation of Unix time was equal to 1234567890. Parties and other celebrations were held around the world, among various technical subcultures, to celebrate this day."need Output asOutput to the browser all numbers greater than 4 digits contained in the given input text using PHP.

View 5 Replies View Related

Output To Browser For Display Before Script Termination?

Jun 7, 2010

Trying to debug a script with loops in it that potentially run for hours or days, and I would like to get intermediate output to the browser before the script terminates. What are the easiest way(s) to do this?Like, for example, is there some way I can output a period character and have it show up in the client browser each time the loop iterates, to make a primitive progress bar?Apologies in advance if this is a newbie question... I've been working with PHP for eight or nine years but I guess this is one thing I never learned.

View 12 Replies View Related

Resize Images Taken By Path And Output It To Browser

Jun 14, 2010

This function doesnt work. It should resize images taken by path and output it to browser. But it do only first photo.

PHP Code:
unction smigas($filename) {
// Get new dimensions
[code]..........

View 4 Replies View Related

Read From A Text File, Output To Browser In Japanese

Jul 17, 2005

I am trying to store data in a text file and output it to the browser
using PHP. All very easy - if I was using English! the problem is, I
want to use Japanese and I'm finding it a tad difficult to get PHP to
understand. I have two files, a text file containing data to display
and a php file with a script to display the data. I can get the
contents of a text file displayed in English, no problemo, but in
Japanese, it's another story...

All the correct settings are enabled in the php.ini file for Japanese
language support (mb_string, input_encoding, output_encoding settings
etc..etc..) even if I save the text file, to be read from, in
Shift_JIS encoding - I still can't get it to display normally!

here's the script I'm using to read the text file :

<?
$filename="test.txt";
$fp = fopen($filename,'r');
while($line=fgets($fp))
{

//output text file line
print $line."<br>";

}
fclose($fp);
?>

View 2 Replies View Related

Output An Image Directly At A Particular Position In The Browser Window

Jan 9, 2007

Is it possible to dynamically create an image (jpeg/gif/png) and output
it directly at a particular coordinate position in the in browser
window using PHP GD functions and HTML (if necessary)?

View 2 Replies View Related

ADVERTISEMENT