PHP: Equivalent of include using eval

后端 未结 8 1259
清酒与你
清酒与你 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:18

    After some more research I found out what was wrong myself. The problem is in the fact that is a "short opening tag" and so will only work if short_open_tag is set to 1 (in php.ini or something to the same effect). The correct full tag is , which has a space after the second p.

    As such the proper equivalent of the include is:

    eval('?>' . file_get_contents('external.php') . '

    Alternatively, you can leave the opening tag out all together (as noted in the comments below):

    eval('?>' . file_get_contents('external.php'));
    

    My original solution was to add a semicolon, which also works, but looks a lot less clean if you ask me:

    eval('?>' . file_get_contents('external.php') . '

提交回复
热议问题