创建whmcs 6 feed来检查客户端是否已登录

问题描述 投票:1回答:2

我正在尝试检查用户是否已登录并显示来自whmcs文件夹外部的名字。我正在使用提要。我已经在feed文件夹中创建了checkifloggedin.php。

<?php
require("../init.php");    
if (isset($_SESSION['uid'])) {

    /*i can get the the id of the user but i cannot display the first
      name of the logged in user. tried several methods but i cannot
      make it work.*/

    widgetoutput();
    }
else {
    widgetoutput('logged out');
}

function widgetoutput($value) {
    echo "document.write('".addslashes($value)."');";
    exit;
}

?>

你们的任何帮助将不胜感激。

非常感谢。

php mysql web whmcs
2个回答
1
投票

我最近想做同样的事情,发现自从较早的人对此问题和类似问题作出答复以来,许多文件名/路径已更改。我的配置一句话-在所有实际用途中,我在public_html / whmcs中都有WHMCS设置。我的索引页面和其他一些页面(关于,术语等)位于public_html(docroot)中。

我所做的第一件事是在public_html中创建一个名为loginin.php的文件,其中包含以下代码:

<?php

$li = 0;

// Define WHMCS namespaces
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;

// Initialize WHMCS client area
define('CLIENTAREA', true);
require __DIR__ . '/whmcs/init.php';
$ca = new ClientArea();

if ($ca->isLoggedIn()) { //logged in
    $clientName = Capsule::table('tblclients')->where('id', '=', $ca->getUserID())->pluck('firstname');
    $ca->assign('clientname', $clientName);
    $li = $clientName[0];
}
else { //not logged in
    $ca->assign('clientname', 'Random User');
}

?>

然后,将其包含在索引文件中:

<?php include("loggedin.php"); ?>

[然后当有人访问主页时,如果他们登录到var $ li =登录用户的名字,而如果$ li = 0,则他们没有登录。我使用它来动态呈现主菜单像这样:

<?php if ($li == "0") : ?>
        <li><a href="#" role="button" data-toggle="modal" data-target="#Login">Login</a></li>
        <li><a href="whmcs/register.php" role="button" class="btn btn-success">Sign Up</a></li>
<?php else : ?>
        <li><a href="whmcs/clientarea.php">Hello, <?php echo $li; ?></a></li>        
<?php endif; ?>

希望可以帮助任何人寻找新的问题答案!


0
投票

我认为您正在寻找使用WHMCS平台的内部API:http://docs.whmcs.com/API:Internal_API

在小部件代码中,您想使用如下代码:

// Set Vars
$command = 'getclientsdetails';
$values = array( 'clientid' => $_SESSION['uid'], 'responsetype' => 'json', );
$adminuser = 'DemoAdmin';

// Call API
$results = localAPI($command, $values, $adminuser);
if ($results['result']!="success") {
    echo "An Error Occurred: ".$results['result'];
    exit;
}

$results = json_decode( $results );

然后$ results应该包含您要查找的用户信息。

© www.soinside.com 2019 - 2024. All rights reserved.