search
HomeBackend DevelopmentPHP Tutorialcreatecompatibledc code that uses bcompiler to encrypt PHP files

Instructions for use:
//Loading function
include_once('phpCodeZip.php');
//Create an encrypted file (sourceDir is the php file directory to be encrypted, targetDir is the encrypted file directory)
$encryption = new PhoCodeZip(' sourceDir','targetDir');
//Execute line encryption
$encryption->zip();
phpCodeZip.php source code download
phpCodeZip.rar
phpCodeZip.php source code content

Copy code The code is as follows :


/*
* @license: MIT & GPL
*/
class PhpCodeZip{
//The source folder to be compressed and encrypted
var $sourceDir = '.';
//The folder to be compressed and encrypted
var $targetDir = 'tmp';
//Whether to encrypt
var $bcompiler = true;
//Whether to remove blank comments and line breaks
var $strip = true;
//Source folder file path array
var $ sourcefilePaths = array();
//array of destination folder file paths
var $targetPaths = array();
//folder size before compression and encryption
var $sizeBeforeZip = null;
//data after compression and encryption Clip size
var $sizeAfterZip = null;
//Output of line break
var $newline = '';
/**
* Constructor
*
* @param string $sourceDir source folder
* @param string $targetDir destination folder
* @param boolean $bcompiler Whether to encrypt
* @param boolean $strip Whether to remove blank comments and line breaks
* @return boolean
*/
public function PhpCodeZip($sourceDir='.',$targetDir=' tmp' ,$bcompiler=true,$strip=true){
//Configure initial variables
$this->sourceDir = $sourceDir;
$this->targetDir = $targetDir;
$this->bcompiler = $bcompiler ;
//Check whether the source data exists
if(!is_dir($this->sourceDir)){
die('The specified source folder'.$this->sourceDir.' does not exist, please reset ');
} else {
//If the specified destination folder exists, cut it off and try again
if(is_dir($this->targetDir)){
echo '[Initialize destination folder]'.$ this ->newline.$this->newline;
$this->cleanDir($this->targetDir,true);
}
//Create a destination folder with the same structure as the source folder
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 file path list of the source folder
$this->sourcefilePaths = $this->getPaths($this- > ;sourceDir,'*');
//Match the file path list of the corresponding destination
foreach($this->sourcefilePaths as $key => $path){
//Set the destination folder file path
$ path = explode('/',$path);
$path[0] = $this->targetDir;
$this->targetPaths[$key] = join('/',$path);
}
//Record the folder size before execution
$this->sizeBeforeZip = $this->getSizeUnit($this->getDirSize($this->sourceDir),2);
echo $this-> newline.$this->newline;
}
}
/**
* Perform compression and encryption
* @return boolean
*/
public function zip(){
$this->newline = '';
echo '【Start encryption process】( Folder size: '.$this->sizeBeforeZip.')'.$this->newline.$this->newline;
//Compress the source file
foreach($this->sourcefilePaths as $ key => $path){
if(is_file($path)){
//Get file information
$pathInfo = pathInfo($path);
echo 'Read source file:'.$path.$this- >newline;
//Get the compressed content
echo '=>Remove blank annotations.....';
if($this->strip && $pathInfo['extension'] == 'php'){
$fileAterZip = php_strip_whitespace($path);
} else {
$fileAterZip = file_get_contents($path);
}
echo 'Finished'.$this->newline;
//Get The compressed content is written to the destination location
$fp = fopen($this->targetPaths[$key],'w+');
echo '=>Write to the destination file..... ';
fwrite($fp,$fileAterZip);
fclose($fp);
echo 'Complete'.$this->newline;
//Whether to choose to encrypt
if($this->bcompiler && $pathInfo['extension'] == 'php'){
echo '=>Encrypt the original file.....';
//Copy the original file
$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);
//Delete the unencrypted original file
unlink($this->targetPaths[$key]);
//Rename the encrypted file
rename($this->targetPaths [$key].'encrypt.php',$this->targetPaths[$key]);
echo 'Finished'.$this->newline;
}
echo $this->newline.$this- >newline;
}
}
//Recalculate the compressed and encrypted folder size
$this->sizeAfterZip = $this->getSizeUnit($this->getDirSize($this->targetDir),2);
echo '[End Encryption program】'.$this->newline.$this->newline;
echo '"Report Information"'.$this->newline;
echo 'Source folder:'.$this->sourceDir .'('.$this->sizeBeforeZip.')'.$this->newline;
echo 'Destination folder:'.$this->targetDir.'('.$this->sizeAfterZip. ')'.$this->newline;
echo 'File size increase: +'.$this->getSizeUnit(($this->getDirSize($this->targetDir) - $this->getDirSize ($this->sourceDir))).$this->newline;
echo 'Total number of files:'.count($this->sourcefilePaths).'.$this->newline;
}
/**
* Delete all files in the directory
*
* @param string $dir The folder to be deleted
* @param boolean $deleteSelf Delete the folder at the same time
* @return void
*/
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);
}
}
/**
* Get the total file size of the folder
*
* @param string $dir The folder to be analyzed
* @return int byte
*/
private function getDirSize($dir='.'){
//Get the file path list
$filePaths = $this->getPaths($dir,'*');
//Initialize the counter
$sizeCounter = 0;
foreach($filePaths as $key => $path){
$sizeCounter = $sizeCounter + filesize($path);
}
return ($sizeCounter);
}
/**
* Get all matching paths of the folder
*
* @param string $start_dir The folder to be analyzed
* @return array File path array
*/
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;
}
/**
* File size unit conversion function
*
* @param int file size
* @param int number of decimal points
* @param boolean whether to cut the data into an array
* @return mix string or array
*/
public function getSizeUnit($size,$decimal=2,$split=false){
//Set unit sequence
$unit = array ('Bytes','KB','MB','GB','TB','PB','EB','ZB','YB');
//Initialization index
$flag = 0;
//Perform simplified division
while($size >= 1024){
$size = $size / 1024;
$flag++;
}
//Whether to separate the value from the unit
if($split){
$ sizeUnit = array(
'size' => number_format($size,$decimal),
'unit' => $unit[$flag]
);
} else {
$sizeUnit = (number_format($size, $ decimal)).$unit[$flag];
}
//Return size and unit
return ($sizeUnit);
}
}

The above introduces the code for createcompatibledc to use bcompiler to encrypt PHP files, including the content of createcompatibledc. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools