简体   繁体   English

在源代码中隐藏/混淆 Javascript 变量

[英]Hiding/Obfuscating A Javascript Variable In The Source

Let's say, for the sake of argument, I have a page with a progress bar that's advancing based on the number of times a certain hashtag has been tweeted on Twitter.假设,为了争论,我有一个带有进度条的页面,该进度条基于某个主题标签在 Twitter 上发布的次数而前进。 This could be generated something like this:这可以生成如下:

tweets = <?php echo $tweetsfile->total; ?>;
target = <?php echo $target; ?>;
$('#progressbar').css('width', tweets / (target/100) + '%');

Supposing that it's undesirable for people to be able to look at the source code and see what the target number is.假设人们不希望能够查看源代码并查看目标数字是多少。 Is there a simple strategy for keeping this information from prying eyes?是否有一种简单的策略可以防止这些信息被窥探?

instead of doing the calculation client side, do it server side.而不是在客户端进行计算,而是在服务器端进行。

$('#progressbar').css('width', <?php echo ($tweetsfile->total / ($target/100)); ?> + '%');

You can simply compute the percentage serverside (php) and not clientside.您可以简单地计算百分比服务器端 (php) 而不是客户端。

$progress = ($tweets / ($target/100));

And output only $progress, which will be the percentage.而 output 只有 $progress,这将是百分比。

$('#progressbar').css('width', $progress + '%');

Try just calculating the percentage in php:尝试只计算 php 中的百分比:

progressPercent = <?php echo (100 * $tweetsfile->total / $target); ?>;
$('#progressbar').css('width', progressPercent + '%');

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

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