What i'd like to achieve
- my php-script is running on: http://execute.tld
- while running i'd like to get content (also scripts) from another website: http://noexecution.tld without execution (compiling) but defer the execution
- now i'd like to execute the content from http://noexecution.tld on http://execute.tld
It's a bit like grabbing global script snippets and compile after putting them together on a different server.
Files
main.php | http://execute.tld/main.php
<?php
$var = 'main.php';
file_put_contents("local_sub.php", file_get_contents("http://noexecution.tld/sub.php") );
include "local_sub.php";
echo $var;
?>
sub.php | http://noexecution.tld/sub.php
sub.php | line 1 notcompiled<br>
<?php $var = 'sub.php | line 2 compiled later<br>'; ?>
sub.php | line 3 notcompiled<br>
Result after running main.php
sub.php | line 1 notcompiled
sub.php | line 3 notcompiled
main.php
Wanted result
sub.php | line 1 notcompiled
sub.php | line 3 notcompiled
line 2 compiled later
My own workaround
My own workaround is to simply switch the extension from sub.php to sub.whatever and rename it "on the fly".
Files
main.php | http://execute.tld/main.php
The sourcecode is the same but changed
file_get_contents("http://noexecution.tld/sub.php") to
file_get_contents("http://noexecution.tld/sub.DontCompileAsPhp").
<?php
$var = 'main.php';
file_put_contents("local_sub.php", file_get_contents("http://noexecution.tld/sub.DontCompileAsPhp"));
include "local_sub.php";
echo $var;
?>
sub.DontCompileAsPhp | http://noexecution.tld/sub.DontCompileAsPhp
The sourcecode is the same but without php extension it will not be compiled as php as well.
sub.php | line 1 notcompiled<br>
<?php $var = 'sub.php | line 2 compiled later<br>'; ?>
sub.php | line 3 notcompiled<br>
Result after running main.php (matches exactly my needs)
sub.php | line 1 notcompiled
sub.php | line 3 notcompiled
line 2 compiled later
Why am I not satisfied with my workaround?
I want to have a clean way to defer the compiling without playing around with extensions...
Things I also tried
__halt_compiler(); [...]ob_start(); [...]
any help is very welcome - thanx in advance | BTW: it's my very first question