douli1306 2014-12-07 05:47
浏览 16

使用PHP保护密钥?

I'm new to JS and PHP and currently have a key I need to use in JavaScript; but I don't want the user to be able to view the code and see it.

I tried putting the key in PHP and echoing it for the JS variable that holds the key, but that will just print it out anyways.

How can I use the key in JavaScript without allowing users to view the source?

EDIT: I'm using an API key to get data and use that data in functions.

  • 写回答

1条回答 默认 最新

  • doudou348131346 2014-12-07 07:18
    关注

    Exactly what is it that you are trying to protect against? Casual use of View Source? A serious attack against your web app by a skilled user? Packet sniffing at Starbucks?

    Sorry, but I've deleted and rewritten this response a dozen times, with a dozen answers depending on your particular situation. Many different security concepts are at play here. The other posters are all correct, in that you can not conceal Javascript from the user. In fact, you cannot conceal anything that is sent to the user's browser. Obfuscation and sessions can help, but aren't perfect.

    That does not mean you can't achieve your security goals.

    But we all need to know what you are trying to achieve!

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探