存储在数据库中的Woocommerce数据的加密格式 [英] Encryption format for Woocommerce data stored in database

查看:98
本文介绍了存储在数据库中的Woocommerce数据的加密格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Wordpress和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:"客户; s:775:" a:25:}

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.

这是什么格式?
如何解析这种格式的值?
如何在php中从此文本数据中检索所有值?

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?

推荐答案

数据采用序列化受保护格式

您可以尝试使用json_decode()unserialize()maybe_unserialize()函数,
但是您不会获得任何数据,因为它是 WC_Session_Handler 存储的 PROTECTED 对象.

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.

您将需要改用 WC_Session_Handler > WC_Session 可用方法.

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

1)要获取当前客户 WC_Session_Handler 对象,您可以使用:

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)要从已定义的客户ID中获取 WC_Session_Handler 对象

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)访问受保护的数据:

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'));

这篇关于存储在数据库中的Woocommerce数据的加密格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆