PHP base64+gzinflate compression encoding and decoding code _php tutorial

Source: Internet
Author: User
Base64+gzinflate compressed encoded (encrypted) files are usually
compression encoding (encryption) code:
Copy CodeThe 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 with compression encoding
$contents = file_get_contents ($filename);//Determine if the file has been encoded
$pos = Strpos ($contents, '/*protected by grass name 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 markings
$headerPos = Strpos ($contents, ' $footerPos = Strrpos ($contents, '?> ');
$contents = substr ($contents, $headerPos +5, $footerPos-$headerPos);
$encode = Base64_encode (Gzdeflate ($contents));//Start coding
$encode = ' ";
Return file_put_contents ($filename, $encode);
}
}
return false;
}
Calling functions
$filename = ' g:\ My Documents \ 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 can be written with compression encoding
$contents = file_get_contents ($filename);//Determine if the file has been encoded
$pos = Strpos ($contents, '/*protected by grass name 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 markings
$headerPos = Strpos ($contents, ' $footerPos = Strrpos ($contents, '?> ');
$contents = substr ($contents, $headerPos +5, $footerPos-$headerPos);
$encode = Base64_encode (Gzdeflate ($contents));//Start coding
$encode = ' ";
Return file_put_contents ($filename, $encode);
}
}
return false;
}
Calling functions
$filename = ' g:\ My Documents \ Desktop \test.php ';
Encode_file_contents ($filename);
?>


compression decoding (decryption) code:
Copy CodeThe code is as follows:
$Code = ' Fill in the code to be decrypted here '; Base64 encoding
$File = ' test.php ';//files saved after decoding
$Temp = Base64_decode ($Code);
$temp = Gzinflate ($Temp);
$FP = fopen ($File, "w");
Fwrite ($FP, $temp);
Fclose ($FP);
echo "Decryption succeeded! ";
?>

http://www.bkjia.com/PHPjc/319481.html www.bkjia.com true http://www.bkjia.com/PHPjc/319481.html techarticle base64+gzinflate Compressed (encrypted) files are usually in the. Eval (Gzinflate (Base64_decode) (a php file for the header. The following we give the relevant encoding decoding (encryption and decryption) ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.