tags:

views:

226

answers:

7

Is it possible to hide the .php file on the server...?

I have a website which sometimes calls php files inside iframes, now I wouldn't like it if somebody copied that code, so how would I hide it? Or do I have to encrypt it?

Speed is a huge matter in my case, so anything that doesn't affect performance is appreciated!

Thanks

+1  A: 

Which code? Your PHP source code? The only code a user see is your html code, PHP is processed on the server side!

Tim
Okay, so they cant in any way get access to it? or somehow download it?
pesar
There's no way they can download your PHP source code. When a `.php` file is requested by a browser, the code in that `.php` file is executed, not displayed.
Daniel May
They can download it, but just via ftp, if the web-server (apache?) is working properly.
DaNieL
+1  A: 

No. The user only sees the HTML code that is generated by your PHP.

Absolutely unequivocally not.

(this is assuming you have PHP installed on your web server. If not, your user will just see the plaintext of the .PHP file - but I'm hoping that this isn't an issue...)

Daniel May
+16  A: 

With a correctly configured web server, the PHP code isn't visible to your website visitors. For the PHP code to be accessible by people who visit your website, the server would have to be configured to display it as text instead of processing it as PHP code.

So, in other words, if you visit your website and you see a HTML page and not PHP code, your server is working correctly and no one can get to the PHP code.

Jeff
A: 

If your php-files are parsed by the http server, nobody can get them.

Martin Hoegh
A: 

If someone access a php file on your site all they will see is the code output by the PHP script (e.g. any HTML, or Javascript) - they won't see the source for the PHP page itself (and will have no way to access it).

If you are concerned about them seeing the output (e.g. the HTML the PHP script generates) from a practical point of view, there isn't anything you can do about that (the most you can do is obfuscate it, but that is largely pointless).

Iain Collins
A: 

I have a website which sometimes calls php files inside iframes, now I wouldn't like it if somebody copied that code, so how would I hide it? Or do I have to encrypt it?

No, that makes no sense and would not work. You have to realize that the PHP code is executed on your server to serve a HTTP request, and that the iframe results in a separate HTTP request from the main page.

If you want to prevent others from including the iframe in their own page, you could check the referrer header and have the iframe page show an error if the referrer is not from your site, but that could cause problems for some legimitate users and can also be circumvented.

Alternative solution: do not use iframes; instead, integrate the PHP code that currently displays the iframe's content in your main page. This will work for all users and cannot be circumvented.

Of course, you still can't prevent others from requesting your page, extracting the content from the HTML and displaying it on their page - that's just how the internet works.

Michael Borgwardt
A: 

If you're still paranoid after the assurances provided here, you can make your code much more difficult for someone else to read by "obfuscating" it (Wikipedia link).

If you Google "php obfuscator", you'll find tons of PHP obfuscator products, many of them free.

Some examples: PHP Obfuscator

Code Eclipse

Professional PHP Obfuscator/Encoder

Obfuscation does not affect performance. Only readability for humans.

DOK