note 56239 added to function.ob-start

From: Date: Sun, 28 Aug 2005 14:29:07 +0000
Subject: note 56239 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-94292@lists.php.net to get a copy of this message
Another way to make your code harder to copy, is to remove all line-breaks and tabs you have in it. You can use this function to remove those. You can choose to place "ob_start();" at the start of your main PHP-file, and "ob_end_clean();" at the end of it. This is not the best solution though. If you are running Apache you might want to do something like this to a ".htaccess"-file: php_value auto_prepend_file "/home/www/load_before.php" php_value auto_append_file "/home/www/load_after.php" (you should replace those files with files that actually exists). In the "load_before.php" you can place the "ob_start();", and in the "load_after.php" you can do something like this: <? $html = strtr(ob_get_contents(), array("\t" => "", "\n" => "", "\r" => "")); ob_end_clean(); echo $html; ?> This will clean your HTML of all kind of linebreaks (both \n and \r) and tabulators (\t). This will save your users some bandwidth, but it will also make your HTML, JavaScripts and more very difficult to read or copy. That way, making it harder for people to steal your code if you do not want them to. This isnt in the spirit of OpenSource, but anyway you should be aware that this is possible. Be aware that if you use PHP-files, to simulate pictures, all linebreaks will also be remove, making them corrupt. A solution to this, could be to check the headers (Content-Type), and if isnt set, or it is "text/html", you can go ahead and remove the linebreaks and tabs. At my site, with more than 50.000 pictures and about 60 people online, I couldnt see any difference in the loadtime. But still be aware, that your output will not be sent, before the script is finished, which will make your page slower to load that way also, since it cannot send any output while loading, but will have to wait until the load is finished. ---- Manual Page -- http://www.php.net/manual/en/function.ob-start.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56239 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56239&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56239&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56239&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56239&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56239&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56239&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56239&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94292) next »