【问题标题】:How to send HTTPS response from a wordpress website to another如何将 HTTPS 响应从 wordpress 网站发送到另一个网站
【发布时间】:2017-09-06 17:17:22
【问题描述】:

我知道这有点复杂,但使用这种方案对我有很多好处,

我正在开发一个 WordPress 项目,需要验证用户的许可证,所以我制作了一个 AJAX 表单,其中包含用户的必填字段,不幸的是验证 API 需要一个密钥(属于我,不能包含在客户的项目中) 所以我制作了一个外部 WordPress 网站(我网站上的子文件夹)并开发了两个小的 [插件和主题]。

- 在客户端

我准备使用 WordPress 函数 (wp_safe_remote_get) 将用户敏感数据发送到我的网站...

$request_url = 'HTTPS://MY_WEBSITE/verify?api=XXX&some=XXX&some=XXX';

$response = wp_safe_remote_get( 

    $request_url, 

    array(
        'timeout' => 300
    )
);

- 在我的网站上

  1. 主题有一个 [3 个文件:style.css、functions.php 和 verify.php],verify.php 有这一行 [do_action('xxx')]。

  2. 该插件在构造函数中有 [ add_action( 'xxx' ) ] 来执行验证过程,当然我在这里包含了 My SECRET KEY ..

  3. 收集 $_GET 参数并验证,然后使用 [print_r] 返回一个带有结果的数组,因此最终结果完全像浏览器检查元素中的这样

    body_tag>

    数组 ( [API_RESULT] => 数组 ('已验证' => true ); )

    /正文>

问题

在客户端,我收到了之前的数组,但是除了很多包含的脚本和 css 路径属于我的 WordPress 网站,所以...

  1. 我只需要接收响应正文而不接收其他包含的文件。
  2. 这足够安全吗?
  3. 是否有针对这种情况的解决方案,例如创建 PHP 文件而不是 WordPress 站点,但会更安全??

感谢您的帮助。

【问题讨论】:

  • 我读过这部分:Unfortunately the verification API needs a Secret Key(Belongs to me and cannot include in the project) 。那么..你曾经使用过公钥/私钥吗?
  • 我在我的网站插件中包含此密钥当然是为了进行验证过程,不能包含在客户的项目中

标签: php wordpress https http-headers xmlhttprequest


【解决方案1】:

1.服务器端

如果您需要将数组发送到客户端,请执行您需要的流程,然后打印序列化数组。

index.php

do_action( 'YOUR_ACTION_NAME', 'VAR_1', 'VAR_2' );

class_processes.php

function __construct() {

    add_action( 'YOUR_ACTION_NAME', array( &$this, '__Trigger_User_Action' ), 10, 2 );

}

public function __Trigger_User_Action( $seller_name = '', $token_type ) {

    $user_final_data = array();

    // Do Some

    die( serialize( $user_final_data ) );

}

2。客户端

$request_url = 'https://DOMAIN.XXX/user_processes?user_name=XXX&code=XXX';

$response = wp_safe_remote_get( 

     $request_url, 
         array(
            'timeout' => 300
         )
     );

     if( ! is_wp_error( $response ) ) {

         $body_data = wp_remote_retrieve_body( $response );

         if( ! is_wp_error( $body_data ) ) {

             $user_server_data = @unserialize( $body_data );

         }

     }

现在 $user_server_data 包含您通过服务器传入 [print] 函数的数组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-21
    • 2011-07-20
    • 1970-01-01
    • 2015-01-07
    • 1970-01-01
    相关资源
    最近更新 更多