0

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?

Jonathan Leffler
760k145 gold badges962 silver badges1.3k bronze badges
asked Jul 20, 2011 at 16:05
5
  • 3
    You do know that by posting the answer here will defeat the purpose of your question? ;) Commented Jul 20, 2011 at 16:07
  • 1
    Serve the width from the server end and then use an ajax call to get the value. Commented 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 difficult Commented Jul 20, 2011 at 16:09
  • @cybernate: should be an answer, it's a valid point Commented 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! Commented Jul 20, 2011 at 19:41

3 Answers 3

2

instead of doing the calculation client side, do it server side.

$('#progressbar').css('width', <?php echo ($tweetsfile->total / ($target/100)); ?> + '%');
answered Jul 20, 2011 at 16:08
Sign up to request clarification or add additional context in comments.

1 Comment

Doh, yes! So simple really. Some days I just can't see the wood for the trees...
1

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 + '%');
answered Jul 20, 2011 at 16:07

Comments

0

Try just calculating the percentage in php:

progressPercent = <?php echo (100 * $tweetsfile->total / $target); ?>;
$('#progressbar').css('width', progressPercent + '%');
answered Jul 20, 2011 at 16:11

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.