octha/obfuscator

使用最简单、最快的方式保护您的 JavaScript 源代码。

dev-main 2022-04-21 07:14 UTC

This package is auto-updated.

Last update: 2024-09-29 02:27:30 UTC


README

License Latest Stable Version Total Downloads

使用 PHP 以最简单、最快的方式混淆 JavaScript 源代码进行保护。

安装

composer require octha/obfuscator

用法

简单用法:混淆 JS 代码

$jsCode = "alert('Hello world!');"; //Simple JS code
$hunter = new \Octha\Obfuscator\Factory($jsCode); //Initialize with JS code in parameter
$obsfucated = $hunter->Obfuscate(); //Do obfuscate and get the obfuscated code
echo "<script>" . $obsfucated . "</script>";

简单用法:混淆 HTML 代码

$htmlCode = "<h1>Title</h1><p>Hello world!</p>"; //Simple HTML code
$hunter = new \Octha\Obfuscator\Factory($htmlCode, true); //Initialize with HTML code in first parameter and set second one to TRUE
$obsfucated = $hunter->Obfuscate(); //Do obfuscate and get the obfuscated code
echo "<script>" . $obsfucated . "</script>";

注意:如果您的 HTML 代码中包含任何 JS 代码,请删除该 JS 代码中的所有注释,以避免出现问题。

设置过期时间

$hunter->setExpiration('+10 day'); //Expires after 10 days
$hunter->setExpiration('Next Friday'); //Expires next Friday
$hunter->setExpiration('tomorrow'); //Expires tomorrow
$hunter->setExpiration('+5 hours'); //Expires after 5 hours
$hunter->setExpiration('+1 week 3 days 7 hours 5 seconds'); //Expires after +1 week 3 days 7 hours and 5 seconds

域名锁定

$hunter->addDomainName('google.com'); //the generated code will work only on google.com

注意:您可以通过逐个添加的方式添加多个域名。

许可证

此软件包受MIT 许可证的许可,© Octha