0

Something like this works:

<?php
  //some variables
  include('/myfile.php');

myfile.php have some html + php code. Now imagine the content of myfile.php is -for reasons not relevant to this question- inside a php variable. The immediate solution is to use eval('?>'.$myFileInAVar.'<?php;'); instead of include, but the scope change when you use it and mess with some functions I have inside myfile.php.

Is there a way to replicate the behavior of include not using a file but the content of it stored in a variable?

DomingoSL
  • 14,920
  • 24
  • 99
  • 173
  • Possibly duplicate of this - http://stackoverflow.com/questions/5948395/require-include-into-variable – Tim Sheehan Mar 30 '16 at 11:06
  • @Dontfeedthecode please read again my question, im not interested on saving the file into a var – DomingoSL Mar 30 '16 at 11:08
  • 1
    Ah you're right I read it wrong, this should be what you're looking for http://stackoverflow.com/questions/4389361/include-code-from-a-php-stream – Tim Sheehan Mar 30 '16 at 11:14

1 Answers1

0

Disclaimer: IT IS A SLIPPERY SLOPE AND IS NOT RECOMMENDED TO ANYONE

If you have allow_url_fopen and allow_url_include enabled, you can use any valid wrapper, e.g. data:// :

<?php
$var = '<?php $a = 18;';

include("data://text/plain;base64,".base64_encode($var));

var_dump($a);  // output: int(18)
Alex Blex
  • 34,704
  • 7
  • 48
  • 75