doulai8128 2016-03-27 17:28
浏览 39

将PHP变量发送到Javascript而不影响“查看源代码”

I'm creating variables through PHP and sending them to Javascript by echo'ing them, then using document.getElementById in JS to grab their values.

The problem with this I have realized is that the elements I am writing with their their php variables are being shown when anyone views the source. It's not behaving like JS where I can write HTML and nothing gets shown on the source (using document.write for example).

How can I send variables from PHP to JS without affecting the viewable source like JS does?

  • 写回答

1条回答 默认 最新

  • douzhoulei8959 2016-03-27 17:51
    关注

    If you want it to behave like JavaScript, you can echo <script> [insert javascript] </script> and write document.write or whatever you choose inside those tags.

    However, there is no way for you to keep it hidden if someone really wants to find out what is happening. HTML and JavaScript are both front-end. Your server is not doing anything at all when it comes to rendering HTML and executing JavaScript; it is all done by the user. And if the user is doing the calculations, the user also knows what is happening.

    I do not see why you would want the HTML to be hidden anyway. Even if one cannot see the source code of HTML, one can still figure out more or less how to replicate what you have done (if the purpose of this is to keep the design a secret).

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题