PHP: Equivalent of include using eval

后端 未结 8 1277
清酒与你
清酒与你 2020-12-06 05:56

If the code is the same, there appears to be a difference between:

include \'external.php\';

and

eval(\'?>\' . file_get_conten

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 06:19

    This lets you include a file assuming file wrappers for includes is on in PHP:

    function stringToTempFileName($str)
    {
        if (version_compare(PHP_VERSION, '5.1.0', '>=') && strlen($str < (1024 * 512))) {
            $file = 'data://text/plain;base64,' . base64_encode($str);
        } else {
            $file = Utils::tempFileName();
            file_put_contents($file, $str);
        }
        return $file;
    }
    

    ... Then include that 'file.' Yes, this will also disable opcode caches, but it makes this 'eval' the same as an include with respect to behavior.

提交回复
热议问题