2017-02-12 7 views
-1

PHP私は非常に特殊な状況があります。PHP - インクルードファイルに定義された変数を取得

私は次のコードを持っている想像してみて:その後、私はしないことを

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

other.php

のindex.php

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

を想像スーズを持ってファイルのコードはother.php(これは奇妙だと思われますが、それを想定しています)。次に、ソースコードindex.phpから、other.phpで定義された変数に関する情報、またはソースコードを取得したいと思います。私の要求では、ファイルの内容を開くことができません: "other.php"。

私はおそらくother.phpの呼び出しの前後にシステムの状態を保存し、状態の差し引きを行って変更内容を確認できますか?

不運にもファイルを操作できません:other.php。 (:other.phpそれは上記のコードで)私はエンコードされたファイルを使用してウェブサイトを持っているので

[UPDATE]

私の問題は、あります。そのエンコードはZend Guard Loaderで行われます。 Zendがここで行うことは、次のコード断片の一番下にあるコード化されたコードをとり、それをある時点でPHPのソースコードに変換してソースコードとして実行することです。私はオリジナルのソースコードを持っていません。コード化されたコードだけです。

次に、そのファイルのソースコードをどうにかしたいと思います。

このコードでは、関数、静的な代入を持つ変数、動的な代入を持つ変数(関数の結果から値を得る)が問題になります。

私にとって理想的なのは、ソースコードを入手する方法です。

ウェブサイトが正しく動作しているため、デコードが正しく行われています。

<?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 ... 
+0

[get_defined_vars()](http://de2.php.net/manual/en/function.get-defined-vars.php)インデックスであなたの 'include'前と後.php、[array_diff()](http://www.php.net/array_diff)を参照してください。 – ccKep

+0

other.phpに 'exec( 'soemthing bad');が含まれていると仮定できますあなたが何であるのかわからない場合はphpファイルを実行しないでください – nogad

+1

基本的に盗みたいので、ファイルは理由のためにエンコードされました – nogad

答えて

0

これは役立つかもしれません(私はちょうどあなたが直接含めるの内容を追加したことに注意して、そのコードは、いくつかの結果に実行可能である...まだちょうどあなたが、その場合には含めるが存在することになる):

<?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:\n"; 
foreach($diff as $d) 
echo "- \$".$d."\n"; 

出力:

New Variables: 
- $x 
- $y 
+0

ありがとうccKep、私は私の本当の理由について私の記事の更新を行いました。あなたの答えは私が必要とするものに非常に近いですが、私はそれが含まれているファイルに関数の結果から変数への代入があるときには正確には当てはまらないと思います。 – Angel

+0

変数がインクルードの後で使用可能である限り(つまりグローバルスコープ内にある)、これはうまくいくはずです。値がどこから来ているかは関係ありません。 – ccKep

関連する問題