duanliang1999 2017-10-29 06:41
浏览 111
已采纳

存储在数据库中的Woocommerce数据的加密格式

I am new to Wordpress and Woocommerce. Looking at the database I came to see few text columns where the stored value looks something like this:

a:23:s:16:"woofc_last_added";s:32:"d770c2ff0c2b832aad82b0cbc3f144a6";s:21:"removed_cart_contents";s:6:"a:0:{}";s:10:"wc_notices";N;s:8:"customer";s:775:"a:25:}

I have stripped most of the fields, but it looks somewhat like this.

What format is this?
How can I parse values in this format?
How can I retrieve all the values from this text data in php?

  • 写回答

3条回答 默认 最新

  • dpt8910 2017-10-29 09:30
    关注

    The data is in a serialized protected format

    You could try to use json_decode(), unserialize() or maybe_unserialize() functions,
    But you will not get any data as it's a WC_Session_Handler stored PROTECTED object.

    You will need to use instead WC_Session_Handler or WC_Session available methods.

    1) To get the current customer WC_Session_Handler object you can use:

    // Get the current WC_Session_Handler obect
    $session_obj = WC()->session;
    
    print_r($session_obj); // Raw output
    

    2) To get the WC_Session_Handler object from a defined customer ID

    // The defined customer ID
    $customer_id = 5;     
    // Get an Instance of the WC_Session_Handler object
    $new_session_obj = new WC_Session_Handler();    
    // The defined customer ID
    $session_obj = $new_session_obj->get_session( $customer_id );
    

    3) Accessing the protected data:

    ## --- Get the data in an array (values are still serialized) --- ##
    
    $session_data_array = WC()->session->get_session_data();
    print_r($session_data_array); // Raw output
    
    
    ## -------------- Get the cleaned unserialized data ------------- ##
    
    $session_cart = WC()->session->get('cart');
    $session_cart_totals = WC()->session->get('cart_totals');
    $session_applied_coupons = WC()->session->get('applied_coupons');
    $session_coupon_discount_totals = WC()->session->get('coupon_discount_totals');
    $session_coupon_discount_tax_totals = WC()->session->get('coupon_discount_tax_totals');
    $session_removed_cart_contents = WC()->session->get('removed_cart_contents');
    $session_shipping_for_package_0 = WC()->session->get('shipping_for_package_0');
    $session_previous_shipping_methods = WC()->session->get('previous_shipping_methods');
    $session_chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
    $session_shipping_method_counts = WC()->session->get('shipping_method_counts');
    $session_customer = WC()->session->get('customer');
    
    // Raw "Cart" output example
    print_r(WC()->session->get('cart'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 应用简单的Python代码完成一个学生成绩管理系统
  • ¥15 用matlab求微分方程初值问题
  • ¥15 vscode下编写第三方库opencv与pcl代码时没有代码提示
  • ¥15 能够跑通不报错,如何解决?(标签-matlab)
  • ¥15 MOS在RDS较大,频率高时开关波形异常
  • ¥15 SCENIC分析报错求解答
  • ¥15 ceph初始化mon不成功 下图不报错 这个是什么元
  • ¥15 数学建模数学建模少ai
  • ¥35 这个等效电路图是什么意思?(答疑)(有没有不是chat的,我就是在chat搜不到才来问的,chat还开了VIP)(可以追加酬金)
  • ¥200 基于同花顺supermind的量化策略脚本编辑