将全局变量导出到有效的PHP文件以实现再现性
我有一个在PHP上运行的web应用程序。它有时会有虫子,我想 能够通过CLI SAPI在本地复制特定请求。我的方式 想象一下这样做:将全局变量导出到有效的PHP文件以实现再现性,php,debugging,webserver,Php,Debugging,Webserver,我有一个在PHP上运行的web应用程序。它有时会有虫子,我想 能够通过CLI SAPI在本地复制特定请求。我的方式 想象一下这样做: <?php // index.php if (!empty($_GET["export_for_debug"]) && DEBUG_MODE) { file_put_contents("request.dat", serialize(get_defined_vars())); } // resume normal execution
<?php
// index.php
if (!empty($_GET["export_for_debug"]) && DEBUG_MODE) {
file_put_contents("request.dat", serialize(get_defined_vars()));
}
// resume normal execution
array("_SERVER" => array("foo" => "bar"))
进入当前范围
编辑: 我明白了。您可以覆盖globals,但似乎需要修改代码 评估。经过一点尝试和错误,我得到了以下结果:
<?php
// get the request variables
$vars = unserialize(file_get_contents("request.dat"));
foreach ($vars as $key => $val) {
eval("\${$key} = \$val;");
}
如果要使用phpdbg
控制台:
1) 将名为.phpdbginit
的文件创建到工作目录中,从中调用phpdbg
。文件内容:
<:
extract(array("_SERVER" => array("foo" => "bar")));
:>
例如,Suhosin确实防止覆盖超全局。如果您仅使用调试器探测变量内容,那么它可能也不会反映最终值状态($\u服务器在运行时被异常修改)。很高兴知道,谢谢@mario。无论哪种方式,它看起来都像是$\u SERVER
无法被覆盖,除非通过eval
。我已经在phpdbg v0.4.0中进行了测试:extract(数组(“\u SERVER”=>array(“foo”=>“bar”))
可以工作,如果它在phpdbginit
脚本文件中使用的话。phpdbg控制台中的命令ev$\u服务器
打印:Array([foo]=>bar)
<:
extract(array("_SERVER" => array("foo" => "bar")));
:>
root@host:/var/www/html# cat .phpdbginit
<:
extract(array("_SERVER" => array("foo" => "bar")));
:>
root@host:/var/www/html# phpdbg -e index.php
[Welcome to phpdbg, the interactive PHP debugger, v0.4.0]
To get help using phpdbg type "help" and press enter
[Please report bugs to <http://github.com/krakjoe/phpdbg/issues>]
[Attempting compilation of /var/www/html/index.php]
[Success]
phpdbg> ev $_SERVER
Array
(
[foo] => bar
)