PHP base64+gzinflate compression encoding and decoding code_PHP tutorial

WBOY
Release: 2016-07-21 15:49:57
Original
939 people have browsed it

The base64+gzinflate compressed encoded (encrypted) file is usually a PHP file with a header of
Compression encoding (encryption) code:

Copy code The code is as follows:

function encode_file_contents($filename) {
$type=strtolower(substr(strrchr($filename,'.'),1));
if('php'==$type && is_file($ filename) && is_writable($filename)){// If it is a PHP file and can be written, compress and encode it
$contents = file_get_contents($filename);// Determine whether the file has been encoded
$pos = strpos($contents,'/*Protected by 草名http://www.crazyi.cn Cryptation*/');
if(false === $pos || $pos>100){ // Remove PHP File comments and whitespace to reduce file size
$contents = php_strip_whitespace($filename);
// Remove PHP header and tail identifiers
$headerPos = strpos($contents,'$footerPos = strrpos($contents,'?>');
$contents = substr($contents,$headerPos+5,$footerPos-$headerPos);
$encode = base64_encode( gzdeflate($contents));//Start encoding
$encode = '";
return file_put_contents($filename,$encode);
}
}
return false;
}
//Call function
$filename='g:My Document Desktop test.php';
encode_file_contents($filename) ;
?>
function encode_file_contents($filename) {
$type=strtolower(substr(strrchr($filename,'.'),1));
if('php'==$type && is_file($filename) && is_writable($filename)){// If it is a PHP file and it is writable, it will be compressed and encoded
$contents = file_get_contents($filename);/ / Determine whether the file has been encoded
$pos = strpos($contents,'/*Protected by 草名 http://www.crazyi.cn Cryptation*/');
if(false === $pos || $pos>100){ // Remove PHP file comments and whitespace, reduce file size
$contents = php_strip_whitespace($filename);
// Remove PHP header and tail identifiers
$ headerPos = strpos($contents,'$footerPos = strrpos($contents,'?>');
$contents = substr($contents,$headerPos+5,$ footerPos-$headerPos);
$encode = base64_encode(gzdeflate($contents));//Start encoding
$encode = '";
return file_put_contents($filename,$encode);
}
}
return false;
}
//Call function
$filename='g:my document Desktop test.php';
encode_file_contents($filename);
?>


Compression decoding (decryption) code:

Copy code The code is as follows:

$Code = 'Fill in the code to be decrypted here'; // base64 Encoding
$File = 'test.php';//Decoded saved file
$Temp = base64_decode($Code);
$temp = gzinflate($Temp);
$FP = fopen($File,"w");
fwrite($FP,$temp);
fclose($FP);
echo "Decryption successful! ";
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319481.htmlTechArticlebase64+gzinflate compressed encoded (encrypted) files usually start with? eval(gzinflate(base64_decode() A php file. Below we give the relevant encoding and decoding (encryption and decryption)...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!