The code that encrypts a PHP file using bcompiler
- 2020-03-31 21:05:25
- OfStack
Instructions:
// load function
Include_once (' phpCodeZip. PHP);
// create the encrypted file (sourceDir to encrypt PHP file directory, targetDir encrypted file directory)
$encryption = new PhoCodeZip (' sourceDir ', 'targetDir');
// perform line encryption
$encryption - > Zip ();
Phpcodezip.php source download
(link: http://xiazai.jb51.net/201008/yuanma/phpCodeZip.rar)
Phpcodezip.php source content
// load function
Include_once (' phpCodeZip. PHP);
// create the encrypted file (sourceDir to encrypt PHP file directory, targetDir encrypted file directory)
$encryption = new PhoCodeZip (' sourceDir ', 'targetDir');
// perform line encryption
$encryption - > Zip ();
Phpcodezip.php source download
(link: http://xiazai.jb51.net/201008/yuanma/phpCodeZip.rar)
Phpcodezip.php source content
class PhpCodeZip{
//To encrypt the password, the password source, the password and the password
var $sourceDir = '.';
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var $targetDir = 'tmp';
//Whether the rows are encrypted
var $bcompiler = true;
//Whether to remove a blank stream to resolve a row
var $strip = true;
//All sources, all materials, all channels and all columns
var $sourcefilePaths = array();
//The purpose is to collect, collect and collect data
var $targetPaths = array();
//The size of the display before the display is encrypted
var $sizeBeforeZip = null;
//The size of the encrypted file and the size of the encrypted file
var $sizeAfterZip = null;
//Everything is fine
var $newline = '';
public function PhpCodeZip($sourceDir='.',$targetDir='tmp',$bcompiler=true,$strip=true){
//Configure the initial
$this->sourceDir = $sourceDir;
$this->targetDir = $targetDir;
$this->bcompiler = $bcompiler;
//The stream checks to see if the source file exists
if(!is_dir($this->sourceDir)){
die(' The specified source and/or material '.$this->sourceDir.' It does not exist. Reschedule ');
} else {
//If the specified target stock exists, cut down the heavy stock
if(is_dir($this->targetDir)){
echo ' [initialize the destination file] '.$this->newline.$this->newline;
$this->cleanDir($this->targetDir,true);
}
//To set up the source and the purpose of the service
mkdir($this->targetDir,0777);
$dir_paths = $this->getPaths($this->sourceDir,'*',GLOB_ONLYDIR);
foreach($dir_paths as $key => $path){
$path = explode('/',$path);
$path[0] = $this->targetDir;
echo '=> '.join('/',$path).$this->newline;
mkdir(join('/',$path),0777);
}
//Get the source, the material, the picture, the way, the clean
$this->sourcefilePaths = $this->getPaths($this->sourceDir,'*');
//With the window of the destination
foreach($this->sourcefilePaths as $key => $path){
//I have a lot to share with you
$path = explode('/',$path);
$path[0] = $this->targetDir;
$this->targetPaths[$key] = join('/',$path);
}
//The size of the display before the display
$this->sizeBeforeZip = $this->getSizeUnit($this->getDirSize($this->sourceDir),2);
echo $this->newline.$this->newline;
}
}
public function zip(){
$this->newline = '';
echo ' 【 password encryption program 】 ( Size: '.$this->sizeBeforeZip.')'.$this->newline.$this->newline;
//All rights reserved
foreach($this->sourcefilePaths as $key => $path){
if(is_file($path)){
//Get all the files
$pathInfo = pathInfo($path);
echo ' - - - - - - - - - - - - '.$path.$this->newline;
//Gets the contents behind the
echo '=> Remove blank solutions ..........';
if($this->strip && $pathInfo['extension'] == 'php'){
$fileAterZip = php_strip_whitespace($path);
} else {
$fileAterZip = file_get_contents($path);
}
echo ' The � '.$this->newline;
//Takes the contents of the rear part to the destination
$fp = fopen($this->targetPaths[$key],'w+');
echo '=> ..........';
fwrite($fp,$fileAterZip);
fclose($fp);
echo ' The � '.$this->newline;
//Whether the rows are encrypted
if($this->bcompiler && $pathInfo['extension'] == 'php'){
echo '=> Encrypt the original stream ..........';
// � � �
$fh = fopen($this->targetPaths[$key].'encrypt.php', "w");
bcompiler_write_header($fh);
bcompiler_write_file($fh, $this->targetPaths[$key]);
bcompiler_write_footer($fh);
fclose($fh);
//The unencrypted original is removed
unlink($this->targetPaths[$key]);
//Rename the private file after the encrypted one
rename($this->targetPaths[$key].'encrypt.php',$this->targetPaths[$key]);
echo ' The � '.$this->newline;
}
echo $this->newline.$this->newline;
}
}
//Re - calculate the size of the encrypted part of the video
$this->sizeAfterZip = $this->getSizeUnit($this->getDirSize($this->targetDir),2);
echo ' 【 beam encryption program 】 '.$this->newline.$this->newline;
echo ' Copyright © 2014 all rights reserved '.$this->newline;
echo ' Copyright © 2014 all rights reserved '.$this->sourceDir.'('.$this->sizeBeforeZip.')'.$this->newline;
echo ' Objectives and materials: '.$this->targetDir.'('.$this->sizeAfterZip.')'.$this->newline;
echo ' Increase in size: +'.$this->getSizeUnit(($this->getDirSize($this->targetDir) - $this->getDirSize($this->sourceDir))).$this->newline;
echo ' In � � � : '.count($this->sourcefilePaths).' � '.$this->newline;
}
private function cleanDir($dir='.',$deleteSelf=true){
if(!$dh = @opendir($dir)) return;
while (($obj = readdir($dh))) {
if($obj=='.' || $obj=='..') continue;
if (!@unlink($dir.'/'.$obj)) $this->cleanDir($dir.'/'.$obj, true);
}
if ($deleteSelf){
closedir($dh);
@rmdir($dir);
}
}
private function getDirSize($dir='.'){
//Get all the information
$filePaths = $this->getPaths($dir,'*');
//Initializes the actor
$sizeCounter = 0;
foreach($filePaths as $key => $path){
$sizeCounter = $sizeCounter + filesize($path);
}
return ($sizeCounter);
}
private function getPaths($sDir, $sPattern, $nFlags = NULL){
$sDir = escapeshellcmd($sDir);
$aFiles = glob("$sDir/$sPattern", $nFlags);
foreach (glob("$sDir/*", GLOB_ONLYDIR) as $sSubDir) {
$aSubFiles = $this->getPaths($sSubDir, $sPattern, $nFlags);
$aFiles = array_merge($aFiles, $aSubFiles);
}
return $aFiles;
}
public function getSizeUnit($size,$decimal=2,$split=false){
//To specify a bit sequence
$unit = array('Bytes','KB','MB','GB','TB','PB','EB','ZB','YB');
//Initialization index
$flag = 0;
//And I'm going to do that
while($size >= 1024){
$size = $size / 1024;
$flag++;
}
//Do you want a value for the display
if($split){
$sizeUnit = array(
'size' => number_format($size,$decimal),
'unit' => $unit[$flag]
);
} else {
$sizeUnit = (number_format($size,$decimal)).$unit[$flag];
}
//Back to the size of the wok
return ($sizeUnit);
}
}