Jump to content

Recommended Posts

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  :-\

Link to comment
https://forums.phpfreaks.com/topic/150594-how-to-encrypt-php-within-javascript/
Share on other sites

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.

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.

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)

 

???

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.