CodeIgniter中的敏感数据

问题描述 投票:1回答:2

我正在构建一个CodeIgniter 2.1.3应用程序,该应用程序将Twitter OAuth API用于多个功能。我在Twitter API的所有令牌都在一个单独的文件app_tokens.php中,git忽略了该文件。我用什么函数将这个文件包含在我的Tweet类中?

app_tokens.php:

<?php 
$consumer_key = 'xxxxxxxxxxxxxxxxxxxxxx';
$consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$user_token = 'xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx';
$user_secret = 'xxxxxxxxxxxxxxxxxxxx';
?>

谢谢!

php codeigniter twitter
2个回答
2
投票

tweet.php文件夹中创建一个名为application/config的文件,并将其放入其中,当然用您的实际数据替换X:

<?php

$config['consumer_key'] = 'xxxxxxxxxxxxxxxxxxxxxx';
$config['consumer_secret'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$config['user_token'] = 'xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx';
$config['user_secret'] = 'xxxxxxxxxxxxxxxxxxxx';

然后在你的Tweet类中通过这样做加载该配置文件:

$this->config->load('tweet');

然后您可以访问这些配置值,如下所示:

$this->config->item('consumer_key');

2
投票

https://www.codeigniter.com/user_guide/libraries/config.html找到了我的答案。谢谢你的帮助!

© www.soinside.com 2019 - 2024. All rights reserved.