ホームページ  >  記事  >  バックエンド開発  >  bcompiler_PHP チュートリアルを使用して PHP ファイルを暗号化するコード

bcompiler_PHP チュートリアルを使用して PHP ファイルを暗号化するコード

WBOY
WBOYオリジナル
2016-07-21 15:34:181176ブラウズ

使用手順:

//関数の読み込み
include_once('phpCodeZip.php');
//暗号化されたファイルを作成します (sourceDir は暗号化される php ファイル ディレクトリ、targetDir は暗号化されたファイル ディレクトリです)
$encryption = new PhoCodeZip( 'sourceDir','targetDir');
//行暗号化を実行
$encryption->zip();

phpCodeZip.php ソースコードの内容


コードをコピーします コードは次のとおりです:

/*
* @license: MIT & GPL
*/
class PhpCodeZip{
//圧縮および暗号化されるソースフォルダー
var $sourceDir = '.'
//圧縮および暗号化されるフォルダー
; var $targetDir = 'tmp';
//暗号化するかどうか
var $bcompiler = true;
var $strip = true;
var $ sourcefilePaths = array();
//宛先フォルダーのファイルパスの配列
var $targetPaths = array();
//圧縮および暗号化前のフォルダーサイズ
var $sizeBeforeZip = null;
//圧縮および暗号化後のデータ
var $sizeAfterZip = null;
//改行の出力
var $newline = '';
/**
* コンストラクター
*
* @param string $sourceDir コピー元フォルダー
* @param string $targetDir コピー先フォルダー
* @param boolean $bcompiler 暗号化するかどうか
* @param boolean $strip 空白のコメントと改行を削除するかどうか
* @return ブール値
*/
public function PhpCodeZip($sourceDir='.',$targetDir=' tmp' , $bcompiler=true,$strip=true){
//初期変数を設定します
$this->sourceDir = $sourceDir;
$this->bcompiler = $bcompiler;
//ソースデータが存在するか確認します

if(!is_dir($this->sourceDir)){
die('指定されたソースフォルダー'.$this->sourceDir.' が存在しません。リセットしてくださいDefine');
} else {
//指定された宛先フォルダーが存在する場合は、それを切断して再試行します
if(is_dir($this->targetDir)){
echo '[宛先フォルダーを初期化]' ->newline.$this->newline;
$this->cleanDir($this->targetDir,true);
//ソースフォルダーと同じ構造の宛先フォルダーを作成します
mkdir ( $this->targetDir,0777);
$dir_paths = $this->getPaths($this->sourceDir,'*',GLOB_ONLYDIR);
foreach($key =>$path) {
$path =explode('/',$path);
$path[0] = $this->targetDir;
echo '.join('/',$path); ;newline;
mkdir(join('/',$path),0777);
}
//ソースフォルダーのファイルパスリストを取得します
$this->sourcefilePaths = $this->getPaths($this - >sourceDir,'*');
//対応する宛先のファイルパスリストと一致する
foreach($this->sourcefilePaths as $key => $path){
//宛先フォルダーのファイルパスを設定
$path =explode('/',$path);
$path[0] = $this->targetDir;
$this->targetPaths[$key] = join('/',$path);
}
//実行前にフォルダーのサイズを記録します
$this->sizeBeforeZip = $this->getSizeUnit($this->getDirSize($this->sourceDir),2);
echo $this-> ;newline.$this->newline;
}
}
/**
* 圧縮と暗号化を実行します
* @return boolean
*/
public function zip(){
$this->newline = '';フォルダー サイズ: '.$this->sizeBeforeZip.')'.$this->newline.$this->newline
//ソース ファイルを圧縮します
foreach($this->sourcefilePaths as $key = > $path){
if(is_file($path)){
//ファイル情報を取得
$pathInfo = pathInfo($path);
echo 'ソースファイルを読み込む:'.$path.$this ->newline ;
//圧縮されたコンテンツを取得します
echo '=>空白の注釈を削除....'
if($this->strip && $pathInfo['extension' ] == 'php'){
$ fileAterZip = php_strip_whitespace($path);
} else {
$fileAterZip = file_get_contents($path);
echo 'Finished'.$this->newline/ / 圧縮されたコンテンツを取得し、宛先の場所
$fp = fopen($this->targetPaths[$key],'w+');
echo '=>宛先ファイルを書き込みます... ..'
fwrite($fp,$fileAterZip) ;
fclose($fp);
echo 'Finished'.$this->newline;
//暗号化を選択するかどうか
if($this-> bcompiler && $pathInfo['extension'] == 'php '){
echo '=>元のファイルを暗号化....'
//元のファイルをコピー
$fh = fopen($ this->targetPaths[$key].'encrypt.php', "w");
bcompiler_write_header($fh);
bcompiler_write_file($fh, $this->targetPaths[$key]);
fclose($fh);元のファイル

unlink($this->targetPaths[$key]);
//暗号化されたファイルの名前を変更します

rename($this ->targetPaths[$key].'encrypt.php',$this-> ;targetPaths[$key]);
echo '完了'.$this->newline;
}
echo $this->newline .$this->newline;
//圧縮および暗号化されたフォルダーのサイズを再計算します
$this->sizeAfterZip = $this->getSizeUnit($this->getDirSize($this->targetDir),2)
echo '[暗号化プログラムの終了] 】'.$this->newline.$this->newline;

echo '"レポート情報"'.$this->newline;
echo 'ソースフォルダー:'.$this-> ('.$this->sizeBeforeZip.')'.$this->newline;
echo '宛先フォルダ:'.$this->targetDir.'('.$this->sizeAfterZip .')' .$this->newline;
echo 'ファイル サイズの増加: +'.$this->getSizeUnit(($this->getDirSize($this->targetDir) - $this-> getDirSize($this ->sourceDir))).$this->newline;
echo 'ファイルの総数:'.count($this->sourcefilePaths).'.$this->newline;

}
/* *
* ディレクトリ内のファイルをすべて削除します
*
* @param string $dir 削除するフォルダ
* @param boolean $deleteSelf フォルダも同時に削除します
* @return void
*/
プライベート関数 cleanDir($dir='.',$deleteSelf=true){
if(!$dh = @opendir($dir)) return; dh))) {
if($obj=='.' || $obj=='..') 続行
if (!@unlink($dir.'/'.$obj)) $this-> ;cleanDir($dir.'/'.$obj, true);
}
if ($deleteSelf){
closedir($dh);
@rmdir($dir)
}
/ **
* フォルダーの合計ファイルサイズを取得します
*
* @param string $dir 解析対象のフォルダー
* @return int byte
*/
private function getDirSize($dir='.'){
//ファイルパスリストを取得
$filePaths = $this->getPaths($dir,'*')
//初期化カウンター
$sizeCounter; = 0;
foreach($key => $path){
$sizeCounter = $sizeCounter + filesize($path);
}
/**
* フォルダーの一致するパスをすべて取得します
*
* @param string $start_dir 分析対象のフォルダー
* @return array ファイルパス配列
* /
プライベート関数 getPaths($sDir, $sPattern, $nFlags = NULL){
$sDir =scapeshellcmd($sDir);
$aFiles = glob("$sDir/$sPattern", $nFlags); ("$sDir/*", GLOB_ONLYDIR) as $sSubDir) {
$aSubFiles = $this->getPaths($sSubDir, $sPattern, $nFlags); }
return $aFiles;
}
/**
* ファイルサイズ単位変換関数
*
* @param int ファイルサイズ
* @param int 小数点数
* @param boolean データを配列に切り出すかどうか
* @return 混合文字列か配列
*/
public function getSizeUnit($size,$decmal=2,$split=false){
//ユニットシーケンスを設定します
$unit = array('バイト','KB','MB','GB','TB','PB','EB','ZB','YB');
//インデックスを初期化します
$flag = 0 ;単純な除算を実行します
while($size >= 1024){
$size = $size / 1024;
}
//値を単位から分離するかどうか
if($split){
$sizeUnit = array(
'size' =>number_format($size,$10 進数),
'unit' => $unit[$flag]
);
} else {
$sizeUnit = (number_format($ size) ,$decmal)).$unit[$flag];
}
//サイズと単位を返す
return ($sizeUnit);



http://www.bkjia.com/PHPjc/322446.html

www.bkjia.com

tru​​e

http://www.bkjia.com/PHPjc/322446.html

技術記事
使用手順: //Load function include_once('phpCodeZip.php'); //暗号化されたファイルを作成します (sourceDir は暗号化される php ファイル ディレクトリ、targetDir は暗号化されたファイル ディレクトリです) $encryption = new PhoCo...

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。