duange051858 2017-02-12 03:21
浏览 54

PHP - 获取包含文件中定义的变量

On PHP I have one very specific situation.

Imagine I have the following code:

index.php

<?
$a = "1";
$b = "2";
include("other.php");
$c = "3";
$d = "4";
?>

other.php

<?
$x = "11";
$y = "12";
?>

Then imagine that I don't have the source code of the file: other.php (this seems weird but assume that). Then, I would like, from the source code of: index.php, get some information about the variables defined on other.php, or maybe the source code. My requirements doesn't allow me to open the content of the file: "other.php".

Could I maybe store the state of the system before and after the call to: other.php and then do a state substraction to see what have changed?

Unfortunatelly I cannot manipulate the file: other.php.

[UPDATE]

My problem, is because I have a website with an encoded file (on the code above it is: other.php). That encoding is done with Zend Guard Loader. What Zend does here is take the encoded code at the bottom of the following fragment of code and convert it to PHP source code at some point and then execute it as source code. I don't have the original source code, just the encoded code.

Then I would like to get the source code of that file somehow.

The problem here is that on this code could be defined functions, variables with static assignments and variables with dynamic assignments (getting it's values from function results).

The ideal for me would be get the source code some how.

The website is working correctly, so, the decoding is done correctly.

<?php @Zend;
4123;
/* This is not a text file */
print <<<EOM
<html><body><a href="http://www.zend.com/products/zend_guard"><img border="0" src="http://www.zend.com/images/store/safeguard_optimizer_img.gif" align="right"></a><center><h1>Zend Optimizer not installed</h1></center><p>This file was encoded by the <a href="http://www.zend.com/products/zend_guard">Zend Guard</a>. In order to run it, please install the <a href="http://www.zend.com/products/zend_optimizer">Zend Optimizer</a> (available without charge), version 3.0.0 or later. </p><h2>Seeing this message instead of the website you expected?</h2>This means that this webserver is not configured correctly. In order to view this website properly, please contact the website's system administrator/webmaster with the following message:<br><br><tt>The component "Zend Optimizer" is not installed on the Web Server and therefore cannot service encoded files. Please download and install the Zend Optimizer (available without charge) on the Web Server.</tt><br><br><b>Note</b>: Zend Technologies cannot resolve issues related to this message appearing on websites not belonging to <a href="http://www.zend.com">Zend Technologies</a>. <h2>What is the Zend Optimizer?</h2><p>The Zend Optimizer is one of the most popular PHP plugins for performance-improvement, and has been available without charge, since the early days of PHP 4. It improves performance by scanning PHP's intermediate code and passing it through multiple Optimization Passes to replace inefficient code patterns with more efficient code blocks. The replaced code blocks perform exactly the same operations as the original code, only faster. </p><p>In addition to improving performance, the Zend Optimizer also enables PHP to transparently load files encoded by the Zend Guard. </p><p>The Zend Optimizer is a free product available for download from <a href="http://www.zend.com">Zend Technologies</a>. Zend Technologies also developed the PHP scripting engine, known as the <a href="http://www.zend.com/products/zend_engine">Zend Engine</a>.</p></body></html>
EOM;
exit();
__halt_compiler();

2003120702‚–ÛUÕ_Eq7X-‡äÂK.½Iëoôïîuolÿ@f*vÈ9õ]¾2003120702‚–ÛUÕ_Eq7X-‡äÂK.½Iëoôïîuolÿ@f*vÈ9õ]¾2003120702‚–ÛUÕ_Eq7X-‡äÂK.½Iëoôïîuolÿ@f*vÈ9õ]¾2003120702‚–ÛUÕ_Eq7X-‡äÂK.½Iëoôïîuolÿ@f*vÈ9õ]¾
... the code continues ...
  • 写回答

1条回答 默认 最新

  • douyan8772 2017-02-12 03:40
    关注

    This might help (note that I just added the contents of your include directly, so the code is runnable with some result... there would still just be your include in that case):

    <?php
    
    $a = 1;
    $b = 2;
    
    $preVars = null; // Define it so it doesn't show up later
    $preVars = array_keys(get_defined_vars());
    
    // Normally included, just here for tests sake
    $x = 10;
    $y = 11;
    // End of your include
    
    $postVars = array_keys(get_defined_vars());
    
    $c = 3;
    $d = 4;
    
    $diff = array_diff($postVars, $preVars);
    
    echo "New Variables:
    ";
    foreach($diff as $d)
    echo "- \$".$d."
    ";
    

    Output:

    New Variables:
    - $x
    - $y
    
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计