Can a client view server-side PHP source code?

前端 未结 7 1764
小鲜肉
小鲜肉 2020-12-01 23:17

I\'m developing a PHP application that has to respond to request from several clients, and I thinks \"Can any of the clients see the PHP code that I\'m writing?\".

相关标签:
7条回答
  • 2020-12-01 23:54

    If you have your webserver set to serve instead of parse your php yes. But then the clients wouldn't work. So the barring any security holes, answer is no.

    0 讨论(0)
  • 2020-12-02 00:01

    Use includes from below or outside the www served directory. (can't +1 yet.. for Frankie)

    Don't use symlinks for your http directories. I've intentionally used this to both show source and execute depending on user request path before, but that required httpd.conf changes (or misconfiguration) and can explicitly be disabled in httpd.conf.

    If allowing downloads of files using fopen, don't pass anything the user creates to it or they could figure out how to get it to grab any file they can find. Consider:

    fopen('reports/' . $_GET['blah']);
    

    where the user passes in '../index.php'

    0 讨论(0)
  • 2020-12-02 00:01

    One mistake for it to happen is to paste a php tag inside a php string, example:

    $string = "This is the answer: <s><?php echo $answer; ?></s>"; 
    echo $string;
    

    The person did a Ctrl+C and Ctrl+V of something that should be printed along the string, but the coder forgot to remove the php tags by distraction.

    0 讨论(0)
  • 2020-12-02 00:06

    No, but you should take all measures to prevent it.

    You should always set your sensitive code (heck, why not all?) in a directory bellow your server working dir (say /www), that way if the server gets messed up, it wont be able to show your code to the world because that code will be included by php that is not working in the first place.

    0 讨论(0)
  • 2020-12-02 00:06

    No. Assuming you've installed a L/UAMP server properly, or aren't printing out (echo, print_r, etc.) and of the guts of your code, the PHP will be processed and the logic or HTML it's meant to output will be used on the page, not visible.

    N.B. If there isn't an 'index' in a directory or a proper .htacess file, an Apache server will show a list of files in the directory, which can be downloaded and reviewed.

    0 讨论(0)
  • 2020-12-02 00:10

    No, unless

    • There is a server misconfiguration
    • There is a bad echo/include somewhere
    0 讨论(0)
提交回复
热议问题