[英]Secure parameter in Codeigniter PHP controller?
我正在嘗試為Coinbase比特幣付款創建回調腳本。 這是我的付款控制器提供的以下功能:
function callback($secret = NULL) {
if ($secret == 'testSECRETkey') {
//If order is "completed", please proceed.
$data = json_decode(file_get_contents('php://input'), TRUE);
$status = $data['order']['status'];
$userid = '507';
if (($status === 'completed')) {
$this->db->query( 'update users set user_money=user_money+15, user_credits=user_credits+5 WHERE users_id=' . $userid );
}
}
如何包含special parameter
,因此當我請求url時: www.example.com/payments/callback
添加特殊密鑰,並且如果拒絕訪問腳本無效,則該參數是無效的。 例:
www.example.com/payments/callback?secret=testSECRETkey
不幸的是,它不能按我的意願工作。 它不會生效。 怎么了
要訪問key
參數,您將使用Input類的get
方法https://ellislab.com/codeigniter/user-guide/libraries/input.html
$this->input->get('key');
function callback()
{
$key = $this->input->get('key');
if( ! $this->is_valid_key($key)) {
// do something here and return
return;
}
//If order is "completed", please proceed.
$data = json_decode(file_get_contents('php://input'), TRUE);
$status = $data['order']['status'];
$userid = '507';
if (($status === 'completed')) {
$this->db->query( 'update users set user_money=user_money+15, user_credits=user_credits+5 WHERE users_id=' . $userid );
}
}
創建一個新方法來驗證密鑰
function is_valid_key($key) {
// logic to check key
$valid = true;
if($valid) {
return true;
}
else {
return false;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.