当前位置:编程学习 > php >>

PHP加密解密文件

加密:
 
01.<?php  
02.  
03.function encode_file_contents($filename) {  
04.  
05.$type=strtolower(substr(strrchr($filename,.),1));  
06.  
07.if(php==$type && is_file($filename) && is_writable($filename)){
// 如果是PHP文件 并且可写 则进行压缩编码  
08.  
09.$contents = file_get_contents($filename);// 判断文件是否已经被编码处理  
10.  
11.$pos = strpos($contents);  
12.  
13.if(false === $pos || $pos>100){ // 去除PHP文件注释和空白,减少文件大小  
14.  
15.$contents = php_strip_whitespace($filename);  
16.  
17.// 去除PHP头部和尾部标识  
18.  
19.$headerPos = strpos($contents,<?php);  
20.  
21.$footerPos = strrpos($contents,?>);  
22.  
23.$contents = substr($contents,$headerPos+5,$footerPos-$headerPos);  
24.  
25.$encode = base64_encode(gzdeflate($contents));// 开始编码  
26.  
27.$encode = <?php." eval(gzinflate(base64_decode("".$encode.""))); ?>";  
28.  
29.return file_put_contents($filename
补充:综合编程 , 安全编程 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,