tags:

views:

80

answers:

3
 <Script Language='Javascript'> <!-- document.write(unescape('<?php if ( ! defined('PROJECTNAME')) exit(''); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;   </body> </html> ')); //--> </Script>

I did not copy paste the whole code. There is more PHP code within the javascript. How to make the browser understand that the php code is php and not treat it as a part of a html code?

EDIT:

Someone I know is asking me to make it hard for bots/novice users to steal source code. Please don't ask me why.

Now, to appease that person I tried encoding and it worked beautifully. Converting everything into %C%22%2F

Now the problem is that it contains php code and that is being encoded. Now if only it took variables from the url and worked like how php should work, then everything will be perfect.

A: 

The browser does not know anything about PHP. PHP runs on the web server. There is no way you are going to evaluate PHP code with Javascript. On the other hand, to execute Javascript with PHP...

Artefacto
A: 

The file extension where you have that code must be PHP. So if it is example.htm you should rename it as example.php

Plus this file should be in Server with PHP in order for the PHP code to be parsed.

Pablo
+2  A: 

Someone I know is asking me to make it hard for bots/novice users to steal source code

Best course of action: beat this person over the head with a large vegetable until they go away.

Your real ‘source code’ is the PHP, and no-one can steal that. As for the HTML, there is absolutely no way you can ever stop anyone “stealing” it. All efforts to try to do so will only make your life hard and your site worse. For example the approach with encoding the whole page in a JavaScript string, which seems to be something like what you're hacking at here, will mess up your site's accessibility and usability, and destroy any hope that search engines might give you a good ranking.

If you did encode HTML in such a broken way, you would have to do it after the PHP code had executed. This is not something you can can do on the PHP source code itself.

bobince
I guess you are right
Karthik Kottapalli
+1 for the vegetable beating
webdestroya