简体   繁体   English

如何使用PHP“隐藏”我的Javascript和CSS文件?

[英]How can I “cloak” my Javascript and CSS files using PHP?

Would it be possible to display different content if someone opened one of my .js or .css files in a browser? 如果有人在浏览器中打开我的.js或.css文件之一,是否可以显示不同的内容? I configured Apache to execute PHP code in .js and .css files. 我将Apache配置为在.js和.css文件中执行PHP代码。 How can I detect if the file was requested by a webpage or viewed directly by an user? 如何检测文件是网页请求的还是用户直接查看的?

Edit: I know there's no way to hide my files 100%. 编辑:我知道没有办法100%隐藏我的文件。 I'm looking for the best way to discourage people from copying my code. 我正在寻找阻止人们复制我的代码的最佳方法。

Nothing on the web that works in a browser can be genuinely cloaked. 真正隐藏在浏览器中的网络上没有任何东西。 The browser is just an agent requesting the file, same as any agent requesting the file for any use. 浏览器只是一个请求文件的代理,与任何请求使用该文件的代理相同。 A server knows no difference between a browser downloading a JS file as part of a web page and a user downloading the JS file to view it. 服务器不知道在浏览器中下载JS文件作为网页的一部分与在用户下载JS文件进行查看之间没有区别。 To the server, they are just requests to download the file. 对于服务器,他们只是请求下载文件。 The server doesn't know what's going to be done with it. 服务器不知道该怎么办。

Even further, JS files and CSS files are usually kept in the disk cache (for performance reasons) where they can be retrieved independent of the server. 更进一步,JS文件和CSS文件通常保存在磁盘缓存中(出于性能原因),可以在其中独立于服务器进行检索。

The only thing you can do is to obscure your code with minification and obfuscation. 您唯一可以做的就是通过最小化和混淆来使代码晦涩难懂。 Minification makes sense because it also makes thing more efficient. 缩小是有道理的,因为它还可以使事情更有效率。 I wouldn't personally recommend obfuscation because it doesn't really stop a determined viewer - it only slows them down slightly. 我个人不建议混淆,因为它并不能真正阻止坚定的观看者-只会稍微放慢他们的速度。 If the browser can understand the JS file to run it, then so can a hacker. 如果浏览器可以理解JS文件来运行它,那么黑客也可以。

In general, people seem to think that their javascript is somehow way more important a secret than it really is. 通常,人们似乎认为他们的javascript比实际要重要得多。 If you do have some sort of secret algorithm that really needs to be protected, then your best bet is to keep the code for that on the server and use ajax calls to access it from your client javascript as needed. 如果确实有某种真正需要保护的秘密算法,那么最好的选择是将代码的代码保存在服务器上,并根据需要使用ajax调用从客户端javascript访问它。

You can detect if the file is called directly by the user checking the HTTP Referrer header. 您可以通过检查HTTP Referrer标头来检测用户是否直接调用了该文件。 But it will not prevent the user to check in Firebug or equivalent tools to see the source of your script. 但这不会阻止用户检入Firebug或等效工具来查看脚本的来源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用php / javascript / css创建图片库? - How can I make an image gallery using php/javascript/css? 当我所有的PHP文件都使用通用标头include时,如何在一个PHP文件中包含CSS文件? - How can I include a CSS file in one PHP file, when all of my PHP files use a common header include? 如何使用JavaScript或PHP在运行时更改HTML元素的CSS属性? - How I can change the CSS properties of HTML elements in run time using JavaScript or PHP? 在使用 css、javascript 和 ZE1BFD762321E409CEEZ4AC0B66 时,我如何限制 HTML 表的打印页面中的特定行数 - how can i restrict no of specific rows in print page for a HTML table in using css , javascript and php 如何在TYPO3中压缩我的js / css文件 - How can I compress my js/css files in TYPO3 如何使用PHP备份服务器文件将文件从服务器上传到Google云存储到Google服务器? - How can I upload files to google cloud storage from my server to google's server using PHP to backup my server files? 我无法在functions.php中添加自定义的CSS和javascript文件 - I could not able to add my custom css and javascript files in functions.php 如何为每个循环将我的JavaScript添加到我的php中? - How can I add my javascript to my php for each loop? 如何在示例PHP代码中添加CSS类 - How can I add a css class to my example php code 如何使用php将文件上传到我的谷歌驱动器(即不是最终用户) - How can I upload files into MY google drive (ie. not the end user's) using php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM