我想要做的是将用户名从网站注入WHMCS。该网站没有与卫生保健中心合并。WHMCS安装在我的网站的一个子目录中。
网站目录结构如下所示:
mywebsite.com
whmcs_directorymywebsite.com是一个有会员的网站。它不是wordpress,它是一个自定义的php站点。
whmcs目录作为我的网站的子目录安装(在网站根目录内的文件夹中)。
我在WHMCS中创建了一个名为"username“的自定义字段。
然后我编写了javascript来注入和填充username字段。我在viewcart.php工作得很好。我所说的“工作良好”的意思是,我可以手动定义任何类似"myvalue“的值,并使用javascript将其包括在内:
<script>
$('document').ready(function () {
$('#customfield1').val('myvalue')
})
</script>我在viewcart.php中包含了这个javascript。它在输入字段中注入myvalue。但是,我不能在里面放任何真正的php,显然每个人的用户名都不是"myvalue“。我需要从whmcs外部获取一个动态php变量。
===========================================================
现在,我能够使用一个名为test.php的原始php文件很好地获取我自己的代码。我可以很容易地将用户名从站点注入到原始php文件中的输入字段。
我只是简单地包含了标题,下面的“获取用户id”代码,编写了一些简短的php来调用它,然后通过javascript注入输入字段。超容易的。
<?php
//get the header
require_once('theheader.php');
// get the user id
$theuser = GetTheUser::loadUser($Auth->id);
// make variable and stuff
$username = $theuser->username;
echo isset($username) ? validation::safeOutputToScreen($username) : '';
?>
<!-- convert to js variable -->
var username = <?php echo json_encode($username); ?>;
<!-- inject username into username input -->
<script>
$('document').ready(function () {
$('#inputfield1').val(username)
})
</script>它在我的原始php页面test.php中工作,并将我的主站点中的登录用户注入到test.php页面的输入字段中。
然而,当我试图将GetTheUser代码(包装在智能{php}{/php}中)包含到viewcart.tpl中时,不幸的是,它会导致一个php错误Fatal error: Class 'GetTheUser' not found in /home/mysite.com/whmcs/vendor/smarty/smarty/libs/SmartyBC.class.php(464) : eval()'d code on line 2。
因此,我只需要得到这个用户名,并将其插入whmcs的购物车页面。
我试图将php代码添加到cart.php中,但结果是whmcs告诉我the file is corrupted php错误页面。不幸的是,在whmcs中不可能将php放入cart.php。
请告诉我如何从mysite.com (我的自定义php站点)获取外部php变量,并将其插入WHMCSmysite.com/ whmcs /cart.php的购物车页面。
发布于 2017-10-25 07:56:02
在WHMCS中,您不编辑核心php文件,而是编辑模板文件,可以在模板文件夹中找到。若要选择“模板”,请使用“常规设置”,请在“常规”选项卡中为“工作区”选择要使用的模板,在“排序”选项卡中选择用于购物车的模板。
您可以按以下方式获得用户名:
网站中的:
mywebsite.com/test.php
添加包含用户名的Get变量的链接:
<a href="mywhmcs/cart.php?act=view&un=someuser"></a>
注意:您可以使用表单发送post请求。
在WHMCS中的
创建以下文件:includes/hooks/website.php
将此代码添加到其中:
<?php
add_hook('ClientAreaPageCart', 1, function($vars) {
if (isset($_GET['un'])) {
$username = filter_var($_GET['un'], FILTER_SANITIZE_STRING);
return array('username' => $username);
}
});这是在访问购物车页面时执行的挂钩。
按顺序排列的模板
(如果不更改默认值,则位于templates/orderforms/standard_cart )
编辑与目标服务相关的文件,例如,注册域名的模板文件是:adddomain.tpl
您可以添加我们在上面钩子中准备的变量,如下所示:
<input type="hidden" name="username" value="{$username}" />
https://stackoverflow.com/questions/46897241
复制相似问题