如何使用 PHP 加密 HTML 源代码输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2834455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:49:06  来源:igfitidea点击:

How to encrypt HTML source code output using PHP

phphtmlencryption

提问by Jeff

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

我想阻止新手用户看到源代码。我有一个生成 html 页面的 php 代码。

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

编辑 1:我遇到了一个简单的工具,它可以将 html 代码加密为 %C%D%F,但它与浏览器一起工作得很好。

采纳答案by Skywalker

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 linkto a free product that does just that.

虽然,正如@Jeff 所说,您无法加密您的 HTML 输出,但您可以对其进行混淆以使其更难以被人类理解。这是一个免费产品的链接,可以做到这一点。

回答by Jeff

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.

您无法加密发送给用户的 HTML 输出。如果您这样做,他们将无法加载网页。

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.

如果您担心他们看到 PHP 代码,则不必担心。他们永远不会看到 PHP 代码 - 它由服务器处理并在发送到客户端之前转换为 HTML。

回答by thetaiko

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

见: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.readyfunction and populate the <body>tag with the product of decryption.

两个简单的库允许您在 PHP 中编码和在 Javascript 中解码。在您的输出中,只需设置 HTML 框架,然后在document.ready函数中使用密钥和加密字符串运行解密,并使用<body>解密产品填充标签。

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.shtmlor Google

当然,这只适用于启用 Javascript。否则使用将看不到任何有用的东西。您还以明文形式传递您的密钥,这很好,因为您只是想阻止“新手”用户访问您的源代码。我也不认为它会真正帮助您防止有人从您的网站获取图像。你最好使用 .htaccess 来做到这一点。查看http://bignosebird.com/apache/a13.shtmlGoogle

回答by shanabus

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

我不认为你可以加密 HTML。它必须由客户端浏览器解释,如果您使用不同的语言,它将不起作用

回答by Barrie Reader

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

您最终可能会厚脸皮并使用它:http: //www.dynamicdrive.com/dynamicindex9/encrypter.htm

It basically encrypted your HTML code into a javascript document.writeline.

它基本上将您的 HTML 代码加密为一个 javascriptdocument.write行。

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

不是真正的加密,但会阻止超过一半的人浏览源代码。

Enjoi.

享受。

回答by Sarfraz

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

您应该改用 javascript 的escape/unescape函数,这样人类就更难破译,而浏览器则不然。