简体   繁体   English

PHP:如何防止直接访问JavaScript文件?

[英]PHP: How to prevent direct access to JavaScript files?

I have seen that some web sites have a PHP script to redirect the user to another web page if they try to access JavaScript files directly. 我已经看到一些网站具有PHP脚本,如果它们尝试直接访问JavaScript文件,则可以将用户重定向到另一个网页。 How is that done? 怎么做?

Unfortunately, as the previous answers have stated, you can't prevent one from seeing the contents of a JS file; 不幸的是,正如前面的回答所述,您不能阻止人们看到JS文件的内容。 if you could do that, how is the browser supposed to parse it? 如果可以的话,浏览器应该如何解析它?

The next best thing to do is to "Obfuscate" it using something like http://www.javascriptobfuscator.com/default.aspx 接下来要做的最好的事情是使用http://www.javascriptobfuscator.com/default.aspx之类的东西“混淆”它

This will convert your human-readable code into a bunch of character codes and obscure function names. 这会将您可读的代码转换为一堆字符代码和模糊的函数名。 The Obfuscator I linked to generates a unique ID and bases its encryption on that ID, making it harder to decrypt. 我链接到的混淆器会生成一个唯一的ID,并将其加密基于该ID,使其难以解密。

However, this isn't fool-proof, and someone who really wants to get at your JS, for whatever reason, will do it. 但是,这并非万无一失,无论出于何种原因,确实想要获得您的JS的人都会这样做。 Anything you really don't want users to have access too should be done server-side. 您确实不希望用户也具有访问权限的所有操作都应在服务器端完成。 ;) ;)

No, that's not possible. 不,那不可能。

There are plenty of ways how to get JS files. 有很多方法来获取JS文件。 Nothing helps in protection. 没有任何帮助的保护。

Javascript is meant to be client side. Javascript应该是客户端。 That means it always gets executed on the browser which is local and thus can not be hidden. 这意味着它总是在本地的浏览器上执行,因此无法隐藏。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM