當(dāng)你不想自己的代碼被別人看到時(shí),你就可以使用gzinflate+base64對(duì)代碼進(jìn)行加密和解密?,F(xiàn)在網(wǎng)上也提供很多base64加密和base64解密工具,可以去百度下!
base64_encode — 使用 MIME base64 對(duì)數(shù)據(jù)進(jìn)行編碼
base64_decode — 對(duì)使用 MIME base64 編碼的數(shù)據(jù)進(jìn)行解碼
php代碼加密和解密原理如下:
<?php
function phpencode($code) {
$code = str_replace(array('<?php','?>','<?PHP'),array('','',''),$code);
$encode = base64_encode(gzdeflate($code));// 開始編碼
$encode = '<?php'."\neval(gzinflate(base64_decode("."'".$encode."'".")));\n?>";
return $encode;
}
function phpdecode($code) {
$code = str_replace(array('<?php','<?PHP',"eval(gzinflate(base64_decode('","')));",'?>'),
array('','','','','',''),
$code);
$decode = base64_decode($code);
$decode = @gzinflate($decode);
return $decode;
}
?>
<form method="post">
<textarea name="source" cols="55" rows="8">
<?php
if(!empty($_POST['source'])) {
if($_POST['button']=='加密') {
echo htmlspecialchars(phpencode(stripcslashes($_POST['source'])));
}
if($_POST['button']=='解密') {
echo htmlspecialchars(phpdecode(stripcslashes($_POST['source'])));
}
}
?>
</textarea>
<?php
if(!empty($_POST['source'])){
if($_POST['button']=='加密') {
echo '<br /><br />加密成功.';
}
if($_POST['button']=='解密') {
echo '<br /><br />解密成功.';
}
}else{
echo '<br /><br />操作失敗';
}
?>
<br /><br />
<input type="submit" name="button" value="加密">
<input type="submit" name="button" value="解密">
</form>
聯(lián)系客服