簡體   English   中英

Codeigniter PHP控制器中的安全參數?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM