简体   繁体   中英

hidding script variables in the main html before passing it to js external file

Please I have a little challenge, I am working on a web app, I want to pass in an id from the main php file to the javascript external file. when i inspect element, the id shows <script> let questId = btoa(<?php echo $_SESSION['questionId']; ?>); </script> <script> let questId = btoa(<?php echo $_SESSION['questionId']; ?>); </script>

when i inspect element, i see the actual id which is wrong, even with the btoa function to encrypt the number from displaying.

Please is there a better way of using php directly on js because i want to use the id to fetch info from the database. Thanks.

Unfortunately you have an incorrect premise. You cannot hide things from the client if the client needs them.

You may find you can generate some intermediate key (perhaps just adding a salt and hashing the real key), which represents the real key in a mapping which is not presented to the client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM