如何使用php代码在ejabbered上注册用户 [英] How to register user on ejabbered using php code

查看:73
本文介绍了如何使用php代码在ejabbered上注册用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从堆栈上发现了一个代码,可以使用php在ejabberd xmpp聊天服务器中执行register命令。 (从PHP创建ejabberd用户)

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:未知用户:ejabberd
sudo:无法初始化策略插件

"sudo: unknown user: ejabberd" "sudo: unable to initialize policy plugin"

我正在我的ubuntu(14.04 LTS 64位)计算机上运行此代码
我正在使用的php代码如下:

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>';
    }
?>

我在<$中使用 localhost c $ c> $ node ,在$ node中,您可以根据在configure.cfg中配置的IP地址使用IP地址。

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()

执行上述链接过程后

User tester@localhost successfully registered

这篇关于如何使用php代码在ejabbered上注册用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆