FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Put gzdeflated item as a string in a PHP file





Mgccl
I found it is not possible for PHP
if there is a string operated by gzdeflate
Code:
<?
//save a gzdeflated PHP code
$fp = fopen("something.php", "w");
$write ='echo gzinflate("';
$write .= gzdeflate('$i=99;while($i>0){$e=$i>1?"s":"";$f=($i-1)>1?"s":"";$b=" of beer";$w=" on the wall";$y=" bottle";$k=$i-1;$j=$i==1?"Go to the store and buy some more, 99 bottles$b":"Take one down and pass it around, $k$y$f$b";echo"$i$y$e$b$w, $i$y$e$b.<br>";$i--;echo"$j$b$w.<br>";}', 9);
$write .= '") ;';
fwrite($fp, $write);
fclose($fp);
//re open the item
$fp = fopen("something.php", "r");
$content = fread($fp, filesize("something.php"));
//now eval the code
eval($content);
?>



I found it is not possible. it show me error, something to do with ASCII codes...
so is that means it's not possible to have a PHP code that contains raw resouce from gzdeflate as a string..?
but I thought there are some 1 file PHP self extracting install systems.
hexkid
You need to escape the result from gzdeflate().

Code:
// Suppose
$x = gzdeflate('hello world');
// turns $x into
$x = 'ab"cd';


If you don't escape it, you'll get an error when you do the eval() thing
Code:
eval('echo gzinflate("ab"cd");');
##                      ^ ERROR!


You need to escape quite a few characters (for ASCII you need to esacpe chr(0) to chr(31), single and double quotes, maybe all characters with a code larger than 127 too). If you want to escape them all, try this:
Code:
// ...
$write ='echo gzinflate("';
$code = gzdeflate('$i=99;/* ... the rest of your bottle code ... */')
for ($j=0; $j<strlen($code); ++$j) {
  $write .= '\\' . decoct(ord($code{$i}));
}
$write .= '") ;';
// ...


Also, specify the mode for the file opening functions.
Code:
$fp = fopen("something.php", "wb");
$fp = fopen("something.php", "rb");

http://php.net/fopen wrote:
If you do not specify the 'b' flag when working with binary files, you may experience strange problems with your data, including broken image files and strange problems with \r\n characters.
Related topics
Cron jobs - running a php file
[PHP doubt]Knowing the directory location of PHP file
[PHP] Dynamic content
File unable to be downloaded
is there any way to trigger a .php file without refreshing?
Uploading a .php file! NEED HELP thanks
How to Make A PHP Portal.
User Viewing A PHP File
send variable from php tp php file
Limiting php file functions with .htaccess
Remote php file access and reading
including javascript in php file
Hide PHP file extension
[TuT]JOOMLA Installation Guide(Easiest Way)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.