yidas/magic-quotes

此包已被废弃且不再维护。作者建议使用yidas/magic-quotes-gpc包。

在PHP 5.4以上版本上实现magic_quotes_gpc以支持旧代码

1.1.0 2018-03-24 07:29 UTC

This package is auto-updated.

Last update: 2019-02-20 19:29:21 UTC


README

在PHP 5.4以上版本实现magic_quotes_gpc以支持旧代码

Latest Stable Version Latest Unstable Version License

如果您正在将旧源代码迁移到PHP版本5.4以上环境中,但包含大量依赖于Magic Quotes magic_quotes_gpc SQL保护的易受攻击的数据库查询代码。只需使用此工具即可在新版本的PHP上顺利运行,就像以前一样。

关于PHP的警告Magic Quotes

自PHP 5.3.0起,Magic Quotes功能已被弃用,自PHP 5.4.0起已移除。

演示

print_r($_GET);
MagicQuotesGpc::init();
print_r($_GET);

访问包含查询?username=1' OR '1'='1的URL后,输出将如下

Array ( [username] => 1' OR '1'='1 ) 
Array ( [username] => 1\' OR \'1\'=\'1 )

递归输入数据关注

来自$_POST$_COOKIE甚至$_GET的递归数据输入也将被处理

$_POST['users'][0] = ['username'=>"1' OR '1'='1"];
print_r($_POST);
MagicQuotesGpc::init();
print_r($_POST);

模拟$_POST数据赋值后,输出将如下

Array ( [users] => Array ( [0] => Array ( [username] => 1' OR '1'='1 ) ) ) 
Array ( [users] => Array ( [0] => Array ( [username] => 1\' OR \'1\'=\'1 ) ) )

安装

通过Composer安装

在您的旧项目中运行Composer

composer require yidas/magic-quotes

然后在应用的引导文件如config文件中初始化它

require __DIR__ . '/vendor/autoload.php';
MagicQuotesGpc::init();

通过加载类直接安装

加载MagicQuotesGpc.php并初始化它

require __DIR__ . '/MagicQuotesGpc.php';
MagicQuotesGpc::init();