fwrite是functions.php中的安全问题?

时间:2019-05-02 05:38:00

标签: php wordpress stripe-payments gravityforms

我需要将stripe_customer_id捕获到wordpress数据库用户元数据中,以便我可以拥有一个前端表单,供用户用来取消Stripe中的订阅。用户将创建一个帐户并以相同的形式注册订阅。

我试图用一个动作和一个过滤器来完成此操作,但由于创建Stripe订阅时用户未登录,因此无法成功完成操作。

我找到了另一个开发人员来帮助我,他们通过将stripe_customer_id写入文本文件,登录用户,然后将ID添加到用户元数据来实现了最终目标。

有人可以告诉我functions.php文件中的以下操作是否构成某种安全风险?

add_action('gform_stripe_customer_after_create', 'save_stripe_customer_id',10,4);

function save_stripe_customer_id( $customer, $feed, $entry, $form)
{
    $fp = fopen("stripdata.txt","w");      
    fwrite($fp,$customer->id);      
    fclose($fp);
}

add_action("gform_user_registered", "autologin", 10, 4);
function autologin($user_id, $config, $entry, $password) {
    wp_set_auth_cookie($user_id, false, '');
    $fp = fopen("stripdata.txt","r");
    $customer_id = trim(fgets($fp));
    fclose($fp);

    update_user_meta($user_id, '_stripe_customer_id',$customer_id);       
}

感谢@EdCottrell的反馈。开发人员使用会话变量重写了代码。您介意快速看一下这段代码并让我知道您的想法吗?

// login user after they register
add_action("gform_user_registered", "autologin", 10, 4);
function autologin($user_id, $config, $entry, $password){
        wp_set_auth_cookie($user_id, false, '');       
        update_user_meta($user_id, '_stripe_customer_id',$_SESSION['customer_id']);
        unset($_SESSION['customer_id']);       
}

add_action('gform_stripe_customer_after_create', 'save_stripe_customer_id',10,4);

function save_stripe_customer_id( $customer, $feed, $entry, $form)
{  

   // $email = rgar( $entry,'14');

    if(!session_id())
    {    
        session_start();
    }

     $_SESSION['customer_id'] = $customer->id;  

}

0 个答案:

没有答案