deerly Posted March 22, 2009 Share Posted March 22, 2009 Hi everyone! I have the following code within a page: <script language="javascript" type="text/javascript"> function setWord(){ word = "<?php echo $word; ?>"; } function setType(){ type = "<?php echo $type; ?>"; } </script> The javascript gets the PHP variables and then passes them to an external JS file that does spiffy things. The problem is that if you view the source on this page (which is a hangman game) javascript spills the beans and says that the word is "whatever the word is"!! Javscript encryption that I've tried breaks the PHP so I am wondering if there is some way to disguise the PHP variables but still make it decipherable to javascript? Sorry if this is in the wrong place :-\ Quote Link to comment https://forums.phpfreaks.com/topic/150594-how-to-encrypt-php-within-javascript/ Share on other sites More sharing options...
Maq Posted March 22, 2009 Share Posted March 22, 2009 The problem I think you're having is the fact that PHP lives on the server and javascript is a client side language. You cannot change the values of the PHP vars without refreshing the page. If you want to use JS you're going to have to use AJAX or you would have to refresh the page to get the new encrypted word. Quote Link to comment https://forums.phpfreaks.com/topic/150594-how-to-encrypt-php-within-javascript/#findComment-791062 Share on other sites More sharing options...
WolfRage Posted March 22, 2009 Share Posted March 22, 2009 Something that may help you though I am not very knowledgable with it, and only looked at it for a day because it grabbed my intrest, but I am not a big fan of javascript. Ymaki DOJO has some scripts that are included with it which have a form of javascript binary encoding. It serves dual purpose, one it makes the scripts faster and more compact but it also makes it extremly hard to decipher. I aquired the package when I downloaded an add on for Netbeans IDE. Quote Link to comment https://forums.phpfreaks.com/topic/150594-how-to-encrypt-php-within-javascript/#findComment-791082 Share on other sites More sharing options...
deerly Posted March 22, 2009 Author Share Posted March 22, 2009 The problem I think you're having is the fact that PHP lives on the server and javascript is a client side language. You cannot change the values of the PHP vars without refreshing the page. If you want to use JS you're going to have to use AJAX or you would have to refresh the page to get the new encrypted word. Hmm, I'm kind of confused ??? This works great I was just wondering if there was a way to set it up so that people viewing the source cannot see what the word is. I have no problem encrypting the PHP within the database before hand but then it seems like javascript would not be able to make heads or tails of it (if it was md5, or whatever) When I try to encrypt the whole thing in a javascript encryptor-dealie it doesn't do any good and confuses everything since the PHP is being echoed and the encryptor is trying to encrypt the PHP tags and not the echoed statement (obviously) ??? Quote Link to comment https://forums.phpfreaks.com/topic/150594-how-to-encrypt-php-within-javascript/#findComment-791103 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.