Forum Moderators: coopster
I want to make a script that encodes the pages with javascript before it gets sent to the client, but I need to figure this out first..
Can anyone help me?
That is probably not the best way, or even a good way to do it. There are all sorts of implications involved with that: it's going to double-up the traffic on your site, it's going to take longer for your server to respond, and trying to organize the URLs could be a pain.
This sounds like a buffering issue. I would check some of the buffering functions on PHP's site to see if there's a way you can redirect the output elsewhere so you can perform further processing on it.
// send all output to the buffer instead of the browser
ob_start();
// include the file, any output from it is stored in the buffer
include 'foobar.php';
// ob_get_clean returns the contens of the buffer, then clears the buffer and switches off output buffering
// so any output beyond this point goes to the browser again and not the buffer
$html = ob_get_clean();
// $html now contains whatever was output by foobar.php
ie ob_start( "myhandler" )
myhandler is a function defined as such:
function myhandler( $bufferin ) {
return $bufferin
}
$bufferin is a string containing whatever was buffered and you return whatever you want to be outputted.
This way you need not put anything at the end of your scripts. At the end of the script the buffer is automatically flushed (or the client woulndn't get any output). When that happens your function is called and it's passed a string containing everything that will be sent to the client. You can at this point change it if you wish.
It's important to note that ob_start() can be layered which is very handy if you want multiple independant handlers to run. They are run in reverse order to which you issued the ob_start command.
ie
ob_start( "handler_1" );
ob_start( "handler_2" );
ob_start( "handler_3" );
at the end of the output handler_3 (being passed whatever the script intends to output) would run then handler_2 would run (but be passed the return value of handler_3) then handler_1 would run (being passed the output of handler_2)
daisho.