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. 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?
-
3You do know that by posting the answer here will defeat the purpose of your question? ;)Mrchief– Mrchief2011年07月20日 16:07:44 +00:00Commented Jul 20, 2011 at 16:07
-
1Serve the width from the server end and then use an ajax call to get the value.Chandu– Chandu2011年07月20日 16:07:50 +00:00Commented Jul 20, 2011 at 16:07
-
you can minify your javascript code, but anybody with a bit of knowledge can reverse the minification/obfuscation (javascript is executed client side and needs to be transferred). the variable will not have its original name, but the used formula will still be the same, so guessing of the original variable is not all that difficultknittl– knittl2011年07月20日 16:09:18 +00:00Commented Jul 20, 2011 at 16:09
-
@cybernate: should be an answer, it's a valid pointknittl– knittl2011年07月20日 16:10:07 +00:00Commented Jul 20, 2011 at 16:10
-
"Let's say, for the sake of argument, I have a page with a progress bar". No you haven't!James– James2011年07月20日 19:41:45 +00:00Commented Jul 20, 2011 at 19:41
3 Answers 3
instead of doing the calculation client side, do it server side.
$('#progressbar').css('width', <?php echo ($tweetsfile->total / ($target/100)); ?> + '%');
1 Comment
You can simply compute the percentage serverside (php) and not clientside.
$progress = ($tweets / ($target/100));
And output only $progress, which will be the percentage.
$('#progressbar').css('width', $progress + '%');
Comments
Try just calculating the percentage in php:
progressPercent = <?php echo (100 * $tweetsfile->total / $target); ?>;
$('#progressbar').css('width', progressPercent + '%');