[英]Hiding/Obfuscating A Javascript Variable In The Source
假設,為了爭論,我有一個帶有進度條的頁面,該進度條基於某個主題標簽在 Twitter 上發布的次數而前進。 這可以生成如下:
tweets = <?php echo $tweetsfile->total; ?>;
target = <?php echo $target; ?>;
$('#progressbar').css('width', tweets / (target/100) + '%');
假設人們不希望能夠查看源代碼並查看目標數字是多少。 是否有一種簡單的策略可以防止這些信息被窺探?
而不是在客戶端進行計算,而是在服務器端進行。
$('#progressbar').css('width', <?php echo ($tweetsfile->total / ($target/100)); ?> + '%');
您可以簡單地計算百分比服務器端 (php) 而不是客戶端。
$progress = ($tweets / ($target/100));
而 output 只有 $progress,這將是百分比。
$('#progressbar').css('width', $progress + '%');
嘗試只計算 php 中的百分比:
progressPercent = <?php echo (100 * $tweetsfile->total / $target); ?>;
$('#progressbar').css('width', progressPercent + '%');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.