Starx
Starx

Reputation: 78941

How to not allow users(or hackers) to download a file directly from web server?

If someone knew the link of one of my page or simply they made an assumption like http://ww.yourweb.com/index.php, this is a general assumption and if you put this link on DAP or other donwload manager, it will download file, with source code inside.

I want to stop other from stealing my code on this manner, is there a way for this?

Upvotes: 0

Views: 429

Answers (4)

Marco Demaio
Marco Demaio

Reputation: 34397

Your server is misconfigured, if running on Apache try adding the follwoing line in the .htaccess file of your root (or public_html) folder and see if you server starts parsing php file properly instead of returning source code.

AddHandler application/x-httpd-php .php

Upvotes: 1

user312650
user312650

Reputation:

Well, I haven't heard of any case of a proper php file being downloaded (i.e. its source code instead of the parsed output).

However, if you want nobody to be able to download some file(s), you should look into mod_rewrite, as it is quite flexible. For example, if you use SMARTY and you don't want your templates to be downloaded (as they give some insight into the structure of your web page/cms/shop/whatever - i.e. make it slightly easier to hack), you can start off with the following rule:

RewriteCond %{REQUEST_URI} \.(tpl|tpl.php)$ 
RewriteRule .* - [F]

Of course that's not enough, but that's a point to start from.

Hope that helps ;)

Upvotes: 0

Robert
Robert

Reputation: 8609

When a HTTP GET request is made on a php resource, the php script is executed by the interpreter on the server, and the resulting html is what is served to the client - not the .php file.

Upvotes: 0

Pekka
Pekka

Reputation: 449385

Your worry is unfounded. If correctly configured, the server will always serve the parsed file, never the unparsed PHP source file, no matter whether it's a browser that requests the file or some download manager.

Upvotes: 7

Related Questions