user244333
user244333

Reputation:

How to encrypt HTML source code output using PHP

I want to deter novice users from seeing the source code. I have a php code that generates a html page.

edit1: I came across a simple tool which encrypted html code into %C%D%F but which worked with the browser just fine.

Upvotes: 17

Views: 39692

Answers (6)

Skywalker
Skywalker

Reputation: 412

While, as @Jeff said, you can't encrypt your HTML output, you can obfuscated it to make it more difficult for a human to understand. Here is a link to a free product that does just that.

Upvotes: 7

thetaiko
thetaiko

Reputation: 7834

See: http://farhadi.ir/works/rc4

Two simple libraries allow you to encode in PHP and decode in Javascript. In your output simply set up the HTML skeleton and then run the decrypt with the key and encrypted string in a document.ready function and populate the <body> tag with the product of decryption.

Of course, this only works with Javascript enabled. Otherwise the use won't see anything useful. You're also passing your secret key in the clear which is fine since you're only trying to prevent "novice" users from accessing your source code. I also don't think it will really help you out that much in preventing someone from grabbing an image from your site. You're much better off working with .htaccess to do that. Check out http://bignosebird.com/apache/a13.shtml or Google

Upvotes: 4

Barrie Reader
Barrie Reader

Reputation: 10713

You could be ultimately cheeky and use this: http://www.dynamicdrive.com/dynamicindex9/encrypter.htm

It basically encrypted your HTML code into a javascript document.write line.

Not really encryption, but will deter over half the people browsing the source.

Enjoi.

Upvotes: 0

shanabus
shanabus

Reputation: 13115

I don't think you can encrypt HTML. It has to be interpreted by the client browser, it wouldn't work if you used a different language

Upvotes: 1

Jeff
Jeff

Reputation: 21892

You can't encrypt the HTML output that is sent to your users. They wouldn't be able to load the web page if you did.

If you're concerned about them seeing the PHP code, you don't have to worry about that. They'll never see the PHP code - it's processed by the server and turned into HTML before sending to the client.

Upvotes: 17

Sarfraz
Sarfraz

Reputation: 382696

You should use javascript's escape/unescape functions instead so that it is harder for humans to decipher but not the browser.

Upvotes: 0

Related Questions