centos 安裝 PHP bcompile 做 編譯/加密原始碼

因有需要研究了一下如何加密php程式碼,發現到 bcompile 似乎滿簡單的,安裝方式如下

yum -y install php-devel php-pear

pecl install bcompiler

編輯 php.ini 並加入下列
extension=bcompiler.so

service httpd restart

使用指令查看是否有安裝
php -m | grep bcompiler
bcompiler

phpinfo(); # 看是否有載入 bcompiler module





 PHP bcompiler 使用

先寫一個編譯程式, 準備把 example.php 編譯成 example.phb (或 xxx.php 都可以), 詳細可見: bcompiler_write_file.
編譯其他程式用的檔案 bcompiler.php


    <?php
    $fh = fopen("example.phb", "w");
    bcompiler_write_header($fh);
    bcompiler_write_file($fh, "example.php");
    bcompiler_write_footer($fh);
    fclose($fh);
    ?>

hello.php


    <?php
    function hello()
    {
       echo "hello\n";
    }
    ?>

example.php


    <?php
    include('hello.php');
    hello();
    ?>

    編譯: php bcompiler.php # 會發現有產生出 example.phb (或於 bcompiler.php 有另外取名字的 xxx.php)
    執行: php example.phb # 會秀 hello, 然後此檔案已經是編譯過的 php code.

如果使用 bcompiler 目的只是要加密 PHP 原始碼,可以直接使用 BENCODER 這支 Script 程式,它最新版本是 v1.4,已經把 bcompiler 加密PHP程式需要的功能,製作成 command-line 工具指令,簡單地呼叫就可以操作。指令的格式如下:

bencoder [-f] [-q] [-t] -o FILE file1.php

安裝 bencoder
wget http://bencoder.urdada.net/bencoder

變更權限
chmod 755 bencoder

複製檔案到執行路徑
cp bencoder /usr/local/bin/

之後就可以使用 bencoder 指令

實際編譯 example.php 會自動產生 FILE 目錄並增加編譯過的 example.php

在瀏覽器中執行 example.php 可以發現到 hello 字樣

開啟編譯過的 example.php 發現到確實以經加密了

缺點:需要手動執行檔案加密,且目前無法解密,只能說免費的軟體使用。

PS:另外有 ionCube、SourceCop、SourceGuardian、phpShield 四款付費的軟體,似乎不錯,ionCube Standalone Encoder 不論功能性、方便性都是四者當中最好的,而且不需在伺服器端安裝任何軟體,在預算許可的範圍下 ionCube Standalone Encoder 的確是最好的選擇。如果不介意主機需安裝載入器,只是要單純保護程式碼不妨選擇 phpShield 。
資料來源:http://www.neo.com.tw/archives/791

留言

這個網誌中的熱門文章

c語言-關於#define用法

CMD常用網管指令

PHP 與 JavaScript 之間傳值利用 json