「PHP入門」gzinflateとbase64_decode暗号、復号プログラム

サンプルコード:

<?php
function encode_file_contents($filename) {
$type=strtolower(substr(strrchr($filename,’.’),1));
if(’php’==$type && is_file($filename) && is_writable($filename)){// 書き込み権限前提に圧縮エンコード
$contents = file_get_contents($filename);// ファイルはエンコードされるかどうか
$pos = strpos($contents,’powered by arkgame.com′);
if(false === $pos || $pos>100){ // ファイルサイズを減らすためphpファイルの注釈と空白を取り除く
$contents = php_strip_whitespace($filename);
// phpヘッダーとフーダーのコードを取り除く
$headerPos = strpos($contents,’<?php’);
$footerPos = strrpos($contents,’?>’);
$contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
$encode = base64_encode(gzdeflate($contents));// エンコード
$encode = ‘<?php’."\n eval(gzinflate(base64_decode(“."’".$encode."’".")));\n\n?>";
return file_put_contents($filename,$encode);
}
}
return false;
}
//メッソッドを呼び出す
$filename=’code.php’;
encode_file_contents($filename);
echo “OK,暗号成功!"
?>

Development

Posted by arkgame