【问题标题】:how to flexible an api to listen a variable in own url?如何灵活的 api 来监听自己 url 中的变量?
【发布时间】:2017-03-16 21:12:15
【问题描述】:

我想灵活地使用这个 whmcs 内部 api 从自己的 url 监听 id 数组。 (即 www.example.com/api.php?pid=2 )。请问有什么帮助吗?

<?php
require_once('init.php');
$command = 'GetProducts';
$postData = array(
    'id' => '1',
);
$adminUsername = 'admin';

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

我使用了下面的代码,但没有成功。

<?php
require_once('init.php');
$command = 'GetProducts';
$prid = $_GET["pid"];
$postData = array(
    'id' => '.'echo $prid;'.',
);
$adminUsername = 'admin';

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

【问题讨论】:

    标签: php api url listener whmcs


    【解决方案1】:

    我通过urlencode($pid)而不是$_GET["pid"]解决了这个问题。

    <?php
    require_once('init.php');
    $command = 'GetProducts';
    $postData = array(
        'pid' => urlencode($pid),
    );
    $adminUsername = 'admin';
    
    $results = localAPI($command, $postData, $adminUsername);
    print_r($results);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 2020-02-01
      • 2012-04-10
      • 2010-12-18
      相关资源
      最近更新 更多