How to register user on ejabbered using php code
I found a code from stack over flow to execute the register command in ejabberd xmpp chat server using php. (Create ejabberd user from PHP)
But when i execute the file i got error:
"sudo: unknown user: ejabberd" "sudo: unable to initialize policy plugin"
I am runing this code on my ubuntu(14.04 LTS 64-bit) machine The php code i am using as follows:
<?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>';
}
?>
I am using localhost
in the $node
, in the $node you can use your ip address as per the ip address you have configure in your configure.cfg.
I have the following error while running the above code
no tty present and no askpass program specified ; TTY=unknown ;
so the below link is the solution for the code below
sudo in php exec()
after executing the above link process
User tester@localhost successfully registered
链接地址: http://www.djcxy.com/p/94158.html
上一篇: 用于服务器端的良好XMPP Java库?