/ / PHPインクルードファイル-関数でそれ自体をオーバーライドします-php、include、include-path

PHPインクルードファイル - 関数内でのオーバーライド - php、include、include-path

ここに私のコードです:

<?php


if(isset($_POST["load_more"])){

$variable = $_SESSION["variable"]++;
generateNewPage($detail_locator, $variable);

}

function generateNewPage($detail_locator, $variable){


$relative_path = "load_more/newfile $variable .php";
$myfile = fopen($relative_path, "a") or die("Unable to open file!");

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

fclose($myfile);

include "load_more/newfile $variable .php";


}


?>
<div id="reload_section">
</ul>
<center><br />
<form  method="post">
<input type="submit" value="Load More" name="load_more" class="load_more_content" />
</form>
</center>
</div>

基本的に、ユーザーがボタンをクリックするたびに、セッションを介して新しいページが生成され、毎回fopenに1が追加されます。

ユーザーがボタンをクリックすると、ページが生成され、そのページが含まれます。

ただし、関数が実行されるたびに、includeステートメントはそれ自体をオーバーライドし、新しく生成されたページの最新のものだけが含まれます。

ユーザーがボタンをクリックすると、生成されたすべてのページが段階的に含まれるようにしたいと思います。

これは可能ですか?もしそうなら、どのように?

@David Jonesの更新:

<?php

if (!isset($_SESSION["files"])) {
$_SESSION["files"] = []; // or array() if your PHP version is < 5.4
}

if(isset($_POST["load_more"])){

$variable = $_SESSION["variable"]++;
generateNewPage($detail_locator, $variable);

}

function generateNewPage($detail_locator, $variable){


$relative_path = "load_more/newfile $variable .php";
$myfile = fopen($relative_path, "a") or die("Unable to open file!");

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

$new_code = "<li><br /><?php kal_generator($detail_locator); ?></li>";
$txt = $new_code;
fwrite($myfile, $txt);

fclose($myfile);

$SESSION["files"][] = "load_more/newfile $variable .php";

foreach ($_SESSION["files"] as $file) {
include $file;
}


}


?>
<div id="reload_section">
</ul>
<center><br />
<form  method="post">
<input type="submit" value="Load More" name="load_more" class="load_more_content" />
</form>
</center>
</div>

回答:

回答№1は0

を追跡するための配列が必要ですファイルパスと関数は、ファイルパスを配列に追加する必要があります。次に、同じ関数またはできれば別の関数で、配列をループして各ファイルを含めます。

したがって、関数の外部で新しい配列を定義します。ここでは、簡単にアクセスできるように、セッションでそれを実行しています。

if (!isset($_SESSION["files"])) {
$_SESSION["files"] = []; // or array() if your PHP version is < 5.4
}

関数で次の行を変更します。

include "load_more/newfile $variable .php";

これに:

$_SESSION["files"][] = "load_more/newfile $variable .php";

次に、ファイル配列をループして、それぞれを含めます。これは、generateNewPage関数または別の関数で実行できますが、generateNewPage関数から呼び出されます。

foreach ($_SESSION["files"] as $file) {
include $file;
}

これが明確であることを願っています。問題があれば教えてください。