开发者

How to post php files on a webserver in plain text

开发者 https://www.devze.com 2023-01-23 13:45 出处:网络
I w开发者_如何学编程ant to post all of my source code for a project on my webserver however I have a problem.All of the source code is in php and when I post it the server tries to execute it.

I w开发者_如何学编程ant to post all of my source code for a project on my webserver however I have a problem. All of the source code is in php and when I post it the server tries to execute it.

To try and avoid this I changed the file extension to .html however this did not work. When I post java files they just show up in plain text is there somehow that I can post php files like this?


the .phps (php source) extension is supported by some servers and will even do source highlighting for you.

You might have to do a AddType application/x-httpd-php-source .phps in the .htaccess file to get this to work properly though.


Change the extension to .txt?


If you're using apache, you can add a .htaccess file in your source directory that contains:

AddType text/plain .php

Alternatively, you can try using the .phps extension if your server is set up for that.


If you are using Apache and mod_php there should be a line in your httpd.conf file with something like:

AddType application/x-httpd-php .php5 .php4 .php

Make sure .html isn't in this list.


use .htaccess directives. unset the php handler and put .htaccess into the directory you want php scripts deny executing


If the .phps extension is not supported by your server you can roll your own.

In .htaccess:

AddType application/x-httpd-php-source .phps

<IfModule mod_rewrite.c>
    RewriteEngine   On

    RewriteCond %{REQUEST_FILENAME} \.phps$
    RewriteRule ^(.*)s$ source.php?file=$1
</IfModule>

And accompanying source.php file:

// Basic filename sanitization
$file = './' . preg_replace("/[^a-zA-Z0-9\/\.-_]/", '', $_GET['file']);

if (file_exists($file)) {
    highlight_file($file);
}


You should run the source code through a code formatter to generate pretty HTML files and publish that as separate HTML documents.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号