0

入力変数に基づいて動的に生成されたページをセットアップするために使用しているphpファイルがあります。単純な文字列ではなく、複雑な Google Earth オブジェクトである変数が収集される index.html ページから開始します。そのページを送信すると、別のページに投稿され、作成されたファイルにリダイレクトされます。ページの生成に使用されるphpインクルードファイル内でその変数を使用しようとすると、問題が発生します。このフォームから変数を適切に取得し、それを通過させて、新しく生成されたページで使用できるようにするにはどうすればよいですか. これが私が現在試していることです。

このボタンをクリックすると、変数 flyto1view が設定されます。

 $("#flyto1").click(function(){          
    if (!flyto1view){
        flyto1view = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
            $("#flyto1view1").val(flyto1view)
    }
    else {
        ge.getView().setAbstractView(flyto1view);

    }
});

次に、ここから非表示フィールドに値を設定しようとしましたが、そのような変数にそのように設定できる値があるかどうかはわかりません。投稿後にこの変数をここに取得する最良の方法は何ですか

<? 
if (isset($_POST['submit']) && $_POST['submit']=="Submit" && !empty($_POST['address']))     {//if submit button clicked and name field is not empty 
$flyto1view1 = $_POST['flyto1']; 
$address = $_POST['address']; //the entered name 
$l = $address{0}; // the first letter of the name 

// Create the subdirectory: 
// this creates the subdirectory, $l, if it does not already exists 
// Note: this subdirectory is created in current directory that this php file is in. 
if(!file_exists($l))  
{  
mkdir($l);  
} 
// End create directory 

// Create the file: 
$fileName = dirname(__FILE__)."/$address.html"; // names the file $name 
$fh = fopen($fileName, 'w') or die("can't open file"); 
// The html code: 
// this will outpout: My name is (address) ! 
$str = "    
<?  php include ('template.php') ?>

"; 
fwrite($fh, $str); 
fclose($fh); 
// End create file 

echo "Congradualations!<br /> 
The file has been created. 
Go to it by clicking <a href=\"$address.html\">here</a>."; 
die(); 
 } 

// The form: 
?> 
4

1 に答える 1

1

まず。ユーザー入力からファイルを作成するのはかなり危険です。おそらくこれはコードの要約にすぎませmkdirんが、最初の文字が実際に文字であり、ドット、スラッシュ、またはその他の文字ではないことを確認せずに、入力の最初の文字から実行することはお勧めできません。

とにかく、あなたの質問に進みます。おそらく $_GET 変数を使用して 2 番目のファイルに渡します。したがって、使用する 2 番目のファイル<?php $_GET['foo'] ?>と最初のファイルで次のようにします。

echo "Congradualations!<br /> 
    The file has been created. 
    Go to it by clicking <a href=\"$address.html?foo=$flyto1view1\">here</a>."; 

次のように、変数をテンプレートにエコーすることもできます。

$str = '
    <?php 
        $var = \'' . $flyto1view1 . '\';
        include (\'template.php\')
    ?>';
于 2013-03-24T19:29:40.347 に答える