将woocommerce数据从php发送到页面以用作javascript安全?

Sending woocommerce data to page from php to be used as javascript safe?

提问人:psml 提问时间:10/28/2023 更新时间:10/28/2023 访问量:20

问:

我在 php 中获取 woocommerce 用户数据并使用 javascript 将该数据添加到 html 输入元素中。买家在woocommerce结帐后收到一封电子邮件。电子邮件中有一个包含订单 ID 的链接。

该 id 在 URL 中传递,如下所示:.然后我使用 php 从 wc_order 对象中获取用户电子邮件和名称。www.mypage.com/some_page/?id=222

该代码运行良好,但我不确定以下过程是否构成安全威胁。任何见解都值得赞赏。

PHP通过WPCode短代码插入到wordpress页面中

if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $order = wc_get_order( $id );
    $billing_email = $order->get_billing_email();
    $billing_first_name = $order->get_billing_first_name();
    $billing_last_name = $order->get_billing_last_name();
    echo "<script>var wc_user = '" . $billing_first_name . " " . $billing_last_name . "'; var wc_email = '" . $billing_email."';</script>";
}

通过 wordpress 页面中的 WPCode 简码的 Javascript

nameInput = document.getElementById("name");
emailInput = document.getElementById("email");   
nameInput.value=wc_user;
emailInput.value=wc_email;
nameInput.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
emailInput.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));      
javascript php wordpress 安全 woocommerce

评论


答: 暂无答案