我正在尝试检查用户是否已记录并显示whmcs文件夹外部的名字。我正在使用提要。我已经在提要文件夹中创建了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;
}
?>
你们的任何帮助将不胜感激。
多谢。
我最近想做同样的事情,发现自从对这个问题和类似问题的旧回复以来,很多文件名/路径都发生了变化。关于我的配置的一句话 - 我在 public_html/whmcs 中设置了 WHMCS 以用于所有实际目的。我的索引页面和其他一些(关于,术语等)都在public_html(docroot)。
我做的第一件事是创建一个名为 loggedin.php 的文件,其中包含以下代码public_html:
<?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; ?>
希望可以帮助任何寻找问题更新答案的人!
我认为您希望使用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应该包含您要查找的用户信息。