简体   繁体   English

如何安全地使用api密钥

[英]How to securely use api key

I am going to make a simple web app. 我打算制作一个简单的网络应用程序。 It will only have a few pages at most, and the main focus of the app is making calls to an api and doing stuff with that info. 它最多只有几页,而应用程序的主要焦点是调用api并使用该信息进行操作。

I want to know what the best way is to keep my api key secure. 我想知道保持api密钥安全的最佳方法是什么。 Are there extremely lightweight frameworks that I can use for this? 我可以使用非常轻量级的框架吗? Should I just create a php page at the root? 我应该在根目录下创建一个php页面吗? I could build something with codeigniter, but that seems like it is too much for what I need. 我可以使用codeigniter构建一些东西,但这似乎对我需要的东西来说太多了。

Keep the API key in a file outside of your web root. 将API密钥保存在Web根目录之外的文件中。 Then include that file in any file that will require its use. 然后将该文件包含在任何需要使用它的文件中。 By placing it outside of the web root it cannot be accessed directly through a web browser or other similar means. 通过将其放置在Web根目录之外,不能通过Web浏览器或其他类似方式直接访问它。

<?php
    // Assuming this file is in the web root
    require('../api_keys.php');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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