将 PHP 文件转换为二进制文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1845197/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert PHP file to binary
提问by Hulk
Is it possible to convert a PHP file to binary and deploy it on a webserver?
是否可以将 PHP 文件转换为二进制文件并将其部署在网络服务器上?
回答by Emre Yazici
回答by Abbas Ali Hashemian
Some months ago I searched for it (php code protection or script protection) and my results were:
几个月前我搜索了它(php代码保护或脚本保护),我的结果是:
I provide some description but try to google them and pardon me.
我提供了一些描述,但尝试用谷歌搜索它们并原谅我。
Be careful with your search because you may encounter to php compressors instead and compressors are just about GZIPand other http transfer compression mechanisms.
搜索时要小心,因为您可能会遇到 php 压缩器,而压缩器GZIP与其他 http 传输压缩机制差不多。
The most important issues with php script protecting tools are:
php脚本保护工具最重要的问题是:
How much speed of php runtime performance will get low(down)(how much speed down)
Will we need an extra environment or installed tools on the php server?
Easy handling
php运行时性能会降低多少速度(下降)(速度下降多少)
我们需要额外的环境或在 php 服务器上安装工具吗?
易于操作
You will find about whole description and comparison on: http://www.seocompany.ca/software/free-encryption-software.html
您可以在以下网址找到完整的描述和比较:http: //www.seocompany.ca/software/free-encryption-software.html
Obfuscators
混淆器
A lot of obfuscators you will find on the web but there's no guarantee for your codes to work.
您可以在网络上找到很多混淆器,但不能保证您的代码能够正常工作。
Even I found a mixed way with Visual C++and MSVSfor obfuscating php and because also I'm experienced with asp.netI tested it however didn't work.
即使我发现了一个混合的方式使用Visual C++和MSVS用于混淆PHP和也因为有我熟悉asp.net我测试然而它没有工作。
Converters and Lockers
转换器和储物柜
ion protector(http://www.ioncube.com/): Oh not free but I heard many about his famous name
phc (php compiler): free and was a good case but "Brendan Long" said the truth because phc has a painful install way. However result is magic and has famous name such as ion
php locker: I got it and test it. It had error with compiled code and it's released for lower than php5. Absolutely not free and for who thinking about ccr-ac*ks finding it for php locker is impossible.
Zend Guard: A perfect way to guard but it's harder than phc or ion because you need Zend runtime environment (ZRE) on your server and Zend Guard is absolutely non-free however if you are a Zend guy (zend framework+zend IDE+zend Guard) you should know Zend Guard is compatible with zend IDE and code blocking process will be so easy. I'm not a Zend guy because either of zend framework and zend guard get down runtime speed obviously. I love php speeded runtime.
php -> C/C++ compiling(YES IT'S POSSIBLE) (BEST PERFORMANCE THROUGH THE WORLD): It's not so famous so it's normal if no one talked about.facebook hiphop: This tool is using by facebook to compile php files on c++/c for getting a better performance however finally we have unreadable compiled codes. I don't remeber but I think it needs a good familiarity to linux or about php recompile mechanism on
Microsoft Visual C++. (However DON'T TRUST to my weak memory and google it) (AND FOR LEARNING ABOUT PHP RECOMPILE WAY PLZ REFER TO latest release of php_manual.chm)
离子保护器(http://www.ioncube.com/):哦不是免费的,但我听说过很多关于他的名声
phc(php 编译器):免费并且是一个很好的例子,但“Brendan Long”说的是实话,因为 phc 有一个痛苦的安装方式。然而结果是神奇的,并有著名的名字,如离子
php locker:我拿到了并测试了它。它在编译代码时出错,并且它的发布版本低于 php5。绝对不是免费的,对于那些考虑 ccr-ac*ks 为 php locker 找到它的人来说是不可能的。
Zend Guard:一种完美的保护方式,但它比 phc 或 ion 更难,因为您的服务器上需要 Zend 运行时环境 (ZRE) 并且 Zend Guard 绝对是非免费的,但是如果您是 Zend 人(zend 框架+zend IDE+zend Guard)您应该知道 Zend Guard 与 Zend IDE 兼容,代码阻塞过程将如此简单。我不是 Zend 人,因为 Zend 框架和 Zend 防护明显降低了运行速度。我喜欢 php 加速运行时。
php -> C/C++ compiling(是的,这是可能的)(全球最佳表现):它不是那么出名,所以如果没有人谈论这很正常。facebook hiphop:facebook使用此工具在 c++/c 上编译 php 文件以获得更好的性能,但最终我们得到了不可读的编译代码。我不记得了,但我认为它需要对 linux 或 .php 上的 php 重新编译机制非常熟悉
Microsoft Visual C++。(但是,不要相信我记忆力薄弱的人并在谷歌上搜索它)(以及了解 PHP 重新编译方式请参考最新版本的 php_manual.chm)
Finally I made my self simple php obfuscator using regular expressions which worked on php 5.3 and my complex scripts so I moved on OpenSSLand different encryption mechanisms and got a review on php secure development.
最后,我使用适用于 php 5.3 的正则表达式和我的复杂脚本制作了我自己的简单 php 混淆器,所以我继续使用OpenSSL不同的加密机制,并获得了关于 php 安全开发的评论。
Wishing you be successful.
祝你成功。
回答by developer68
This is way overdue but should do what you want.
这是过期的方式,但应该做你想做的。
Make your own custom extension with the zend engine as they compile to a c++ dll. Add that dll to your ext location in the php directory. After that you can call your own php scripts as php functions. Keep in mind that php is server side only so no one can get your scripts unless they are copied from the server and handed out.
使用 zend 引擎制作您自己的自定义扩展,因为它们编译为 c++ dll。将该 dll 添加到 php 目录中的 ext 位置。之后,您可以将自己的 php 脚本作为 php 函数调用。请记住,php 只是服务器端,因此除非从服务器复制并分发脚本,否则没有人可以获取您的脚本。
Download the php source library for the version that you have. [windows.php.net] The zend stuff you need will be included.
下载您拥有的版本的 php 源库。[windows.php.net] 你需要的zend 东西都会被包括在内。
Step 1. Create a new project and select "General" under Visual C++ and the empty project option. Give it a name and Click ok. Mine is Project1 so I will be using that.
步骤 1. 创建一个新项目并选择 Visual C++ 下的“常规”和空项目选项。给它一个名字,然后单击确定。我的是 Project1,所以我将使用它。
Step 2. Right click the solution name and select properties. Select Dynamic Library (.dll) Under Project Defaults/Configuration Type in the Configuration Properties/General item. Be sure that you are changing the Debug config as Release is not used.
步骤 2. 右键单击解决方案名称并选择属性。在 Configuration Properties/General 项中的 Project Defaults/Configuration Type 下选择 Dynamic Library (.dll)。确保您正在更改调试配置,因为未使用 Release。
Step 3. Under VC++ Directiories add the following under the Include libraries: C:\php-7.1.8-src\Zend C:\php-7.1.8-src\win32 C:\php-7.1.8-src\TSRM C:\php-7.1.8-src\main C:\php-7.1.8-src Libraries: C:\php-7.1.8\dev
步骤 3. 在 VC++ Directiories 下的 Include libraries 下添加以下内容: C:\php-7.1.8-src\Zend C:\php-7.1.8-src\win32 C:\php-7.1.8-src\TSRM C:\php-7.1.8-src\main C:\php-7.1.8-src 库:C:\php-7.1.8\dev
Step 4. Under C/C++ Preprocessor add ZEND_DEBUG=0;ZTS=1;ZEND_WIN32;PHP_WIN32 to Preprocessor Definitions
步骤 4. 在 C/C++ Preprocessor 下添加 ZEND_DEBUG=0;ZTS=1;ZEND_WIN32;PHP_WIN32 到 Preprocessor Definitions
Step 5. Under Linker Input add php7ts.lib. This needs to match the lib for your version of php
步骤 5. 在链接器输入下添加 php7ts.lib。这需要与您的 php 版本的 lib 匹配
Click ok to save the Property settings for your solution.
单击确定以保存解决方案的属性设置。
Now lets add a code file for your function (Project1)
现在让我们为您的函数(Project1)添加一个代码文件
Under the source files folder right click and add Code. I called mine Project1.cpp and here is the source. You'll need to rename config.w32.h.in to config.w32.h and copy it to the directories where it is needed. Intellisense should tell you where it's looking and config.w32.h.in is in the C:\php-7.1.8-src\win32 directory.
在源文件文件夹下右键单击并添加代码。我打电话给我的 Project1.cpp,这里是来源。您需要将 config.w32.h.in 重命名为 config.w32.h 并将其复制到需要它的目录中。Intellisense 应该会告诉您它在哪里,config.w32.h.in 位于 C:\php-7.1.8-src\win32 目录中。
// this needs to match the compiler version that php was compiled with
#define _CRT_SECURE_NO_WARNINGS
#define PHP_COMPILER_ID "VC14"
#pragma once
/* You must include config.w32.h first */
#include "win32/config.w32.h"
#include "php.h"
ZEND_FUNCTION(ReturnString);
zend_function_entry Project1_functions[] =
{
ZEND_FE(ReturnString, NULL)
{
NULL, NULL, NULL
}
};
zend_module_entry Project1_module_entry =
{
STANDARD_MODULE_HEADER,
"Project1 Module",
Project1_functions,
NULL, NULL, NULL, NULL, NULL,
NO_VERSION_YET, STANDARD_MODULE_PROPERTIES
};
ZEND_GET_MODULE(Project1)
ZEND_FUNCTION(ReturnString)
{
zval* value;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE)
{
RETURN_FALSE;
}
convert_to_string(value);
RETURN_STRING(Z_STRVAL_P(value), true);
}
Press F7 to compile and it should create Project1\Debug\Project1.dll. Copy Project1 to your ext directory C:\php-7.1.8\ext and add an extension=Project1.dll to your php.ini and you should be good to go. If it doesn't work double check your properties to make sure you didn't miss something.
按 F7 编译,它应该创建 Project1\Debug\Project1.dll。将 Project1 复制到您的 ext 目录 C:\php-7.1.8\ext 并将 extension=Project1.dll 添加到您的 php.ini 中,您应该很高兴。如果它不起作用,请仔细检查您的属性以确保您没有遗漏任何东西。
The script is quite simple:
<?php
echo ReturnString("The Returning String");
?>
回答by Zac Bowling
It depends on what you mean by "binary".
这取决于你所说的“二进制”是什么意思。
If you want to compile (or just obfuscate) your PHP code to keep someone else from modifying then use a bytecode compiler. One example are the tools from Zend, among others. (I prefer Zend's tools because they the primary company behind PHP and fully QA all their tools against all the versions of PHP).
如果您想编译(或只是混淆)您的 PHP 代码以防止其他人修改,请使用字节码编译器。其中一个例子是来自Zend的工具。(我更喜欢 Zend 的工具,因为它们是 PHP 背后的主要公司,并且针对所有版本的 PHP 对所有工具进行了全面质量检查)。
If you want to compile your PHP code and link the PHP runtime to it and then deploy it (like C\C++), then no. Maybe in theory that would be possible but it would be a mess. (Not practical or feasible and don't think anyone has put anything together to try and the output would also be tied to a particular architecture).
如果你想编译你的 PHP 代码并将 PHP 运行时链接到它,然后部署它(如 C\C++),那么不。也许理论上这是可能的,但它会一团糟。(不切实际或不可行,不要认为任何人都将任何东西放在一起尝试,并且输出也将与特定架构相关联)。

