doq91130 2015-05-24 12:33
浏览 1029

从浏览器隐藏API密钥

I have an API Key that I use to retrieve information which is displayed on the browser. The problem I have is that using Chrome - Inspect Element - Source, the API key can be viewed. The code look like the following:

<meta charset="utf-8">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <link href="/styles.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript">
        //<![CDATA[
         var dbtKey = "<?php echo $apiKey; ?>"; 

The $apiKey is a var which sits in my config.php file: $apiKey = 'my key'

Is there any way I can prevent this from being displayed?

  • 写回答

1条回答 默认 最新

  • doutu4335 2015-05-26 23:17
    关注

    You would need to handle all the request via PHP and return the result as JSON which you can process client side.

    For extra security, use SSL which will help against external threats but not internal.

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮