如何使用php代码在ejabbered上注册用户
我发现了一个来自堆栈溢出的代码,用php执行ejabberd xmpp聊天服务器中的register命令。 (从PHP创建ejabberd用户)
但是当我执行文件时出现错误:
“sudo:未知用户:ejabberd”“sudo:无法初始化策略插件”
我在我的ubuntu(14.04 LTS 64位)机器上运行这段代码我使用的php代码如下:
<?php
$username = 'tester';
$password = 'testerspassword';
$node = 'myserver.com';
exec('sudo -u ejabberd /usr/sbin/ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1',$output,$status);
if($output == 0)
{
// Success!
}
else
{
// Failure, $output has the details
echo '<pre>';
foreach($output as $o)
{
echo $o."n";
}
echo '</pre>';
}
?>
<?php
$username = 'tester';
$password = 'testerpassword';
$node = 'localhost';
echo exec('sudo -u ejabberd /usr/sbin/ejabberdctl register '.$username.' '.$node.' '.$password.' 2>&1',$output,$status);
die;
if($output == 0)
{
// Success!
echo "success";
}
else
{
// Failure, $output has the details
echo '<pre>';
foreach($output as $o)
{
echo $o."n";
}
echo '</pre>';
}
?>
我在$node
使用localhost
,在$node
,您可以根据您在configure.cfg中配置的IP地址使用您的IP地址。
运行上述代码时出现以下错误
no tty present and no askpass program specified ; TTY=unknown ;
所以下面的链接是下面代码的解决方案
sudo在PHP exec()
执行上述链接过程后
User tester@localhost successfully registered
链接地址: http://www.djcxy.com/p/94157.html