茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1675302 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_00018.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2010/11/18 4:00:38

使用 bcompiler 來編譯(加密)您的 PHP 原始碼

Using bcomipler to compile (encode) your PHP script (in FreeBSD)

eAccelerator 的 encoder 在 PHP 5.1 以後就無法運作了,使是最新的版本 0.9.5 也不行,因此如果您還想用 eAccelerator 的 encoder,乖乖待在 PHP 4.x or PHP 5.0 吧,相關資訊可參考之前的兩篇文章:

根據 mailing list 上面作者最新的 說法,短期內應該都還不會修復,甚至有可能還會放棄支援 encoder 部份,作者還推薦大家改用
bcompiler ... orz
所以如果你跟我一樣必須要用 PHP 5.1 的話,就跟我一起來玩看看 bcompiler

附帶一提,原本是要買 ionCube 公司開發的 PHP Encoder 的,這看來是目前編譯(加密)PHP 原始碼最好的選擇,價格也不算貴,而且花的是公司的錢,不過還是先試用看看 bcompiler 好了,真的不好用的話,再來買囉

以下的安裝與使用說明均以 FreeBSD 為範例,其他作業系統應該也差不多,請自己試看看吧

在正式安裝之前提醒你, bcompiler 會用到 bzip2 這個 extension,所以先安裝一下 php5-bz2:


# cd /usr/ports/archivers/php5-bz2
# make install clean

bcompiler 是一個收容於 PECL 的 PHP extension,您可以直接使用 pecl 這個命令來安裝,而 pecl 的使用方法與 pear 相同,因此你必須先安裝 pear :


# cd /usr/ports/devel/pear
# make install clean

pear 安裝好後,同時會有一個 pecl 命令可用 (/usr/locel/bin/pecl),可用它來安裝 bcompiler

pecl install channel://pecl.php.net/bcompiler-0.8

不過呢,我發現直接執行 pecl 會發生錯誤(至少在 FreeBSD 下是如此):


# pecl
Fatal error: Call to undefined function preg_match() in ...

問題出在 /usr/local/bin/pecl 這個 script 的最後一行:

exec $PHP -C -n -q $INCARG -d output_buffering=1 -d safe_mode=0 ...

這一行的 -n 這個選項代表不載入 php.ini 設定檔,因此 pcre.so 就沒有被載入,
然後你就看到上面的錯誤了,所以自己去改一下程式把 -n 拿掉吧....

拿掉之後,安裝程式應該就可以正常運作了了:

pecl install channel://pecl.php.net/bcompiler-0.8

安裝好後,記得要改設定把 bcompiler 這個 extension 載入

> /usr/local/etc/php/extensions.ini

bcompiler 全名是 PHP bytecode Compiler,詳細的使用方法可以參考 PHP 網站上的詳細說明: PHP bytecode Compiler: http://www.php.net/manual/en/ref.bcompiler.php

看不懂的話, bcompiler_write_file() 這個 function 的說明裡面有範例:


bcompiler_write_header($fh);
bcompiler_write_file($fh, "example.php");
bcompiler_write_footer($fh);
fclose($fh);

為了易於使用,我寫了一個簡單的 script,使用方法如下:


BENCODER v1.3 - Encode your PHP script using bcompiler
Usage: bencoder [-f] [-q] -o FILE file1.php
bencoder [-f] [-q] -o OUTDIR file1.php file2.php ...
bencoder [-f] [-q] -o OUTDIR -s SRCDIR [-e SUFFIX] [-r] [-c] [-l]
-o FILE : the file name to write the encoded script
(default to '-encoded.XXX' suffix)
-o OUTDIR : the directory to write all encoded files
-a SRCDIR
-s SRCDIR : encode all files in this source directory
-r : encode directories recursively (no by default)
-f : force overwriting even if the target exists
-e SUFFIX : encode the files with the SUFFIX extension only (default: php)
(regular expression allowed, ex: "php|inc")
-c : copy files those shouldn't be encoded (no by default)
-l : follow symbolic link (no by default)
-q : do not print the file name while encoding or copying
-b
-bz2 : compress the encoded files with bz2 (needs bzip2-extension)

想用的人到 這邊 自己抓回去玩玩看吧


# wget http://bencoder.urdada.net/bencoder
# chmod 755 bencoder
# mv bencoder /usr/local/bin/

在把程式使用 bcompiler 編碼之後,執行的時候發覺 $_SERVER 以及 $_ENV 的變數都不見了,後來查了資料,才發現要把 auto_globals_jit 關掉 (Off) 才行,請直接修改您的 php.ini :


; When enabled, the SERVER and ENV variables are created when they're first
; used (Just In Time) instead of when the script starts. If these variables
; are not used within a script, having this directive on will result in a
; performance gain. The PHP directives register_globals, register_long_arrays,
; and register_argc_argv must be disabled for this directive to have any affect.
auto_globals_jit = Off


原文出處: 使用 bcompiler 來編譯(加密)您的 PHP 原始碼 | Dada's Blog
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|