Display PHP code in browser from the same source script

前端 未结 4 1002
旧巷少年郎
旧巷少年郎 2020-12-20 07:58

Is there a way to display the source code of somepage.php when you go to somepagesrc.php? IOW, is there a PHP function that will in somepage

相关标签:
4条回答
  • 2020-12-20 08:22

    Try easily to read its contents as any file using the file manipulation functions :) I don't know if that may be the solution you are searching about :$

    0 讨论(0)
  • 2020-12-20 08:26

    or you could use Reflection through which you could easily get functions, variables, and even comments.

    http://www.php.net/manual/en/intro.reflection.php

    0 讨论(0)
  • 2020-12-20 08:36

    Take a look at highlight_file(). It not only grabs the php source to display (like file_get_contents()) but nicely formats/colorizes the code for output.

    http://php.net/manual/en/function.highlight-file.php

    0 讨论(0)
  • 2020-12-20 08:46

    Maybe use file_get_contents along with header('Content-type: text/plain') - but obligatory security warning - be sure to filter the names of files so people can't include more than you intent.

    E.g.:

    <?php
    
    header('Content-type: text/plain');
    
    print file_get_contents("somepage.php");
    
    ?>
    
    0 讨论(0)
提交回复
热议问题