Home » Php » how can create a ejjabbered user using php script?

how can create a ejjabbered user using php script?

Posted by: admin October 26, 2017 Leave a comment

Questions:

Please help me to register user in ejjabered using php. I have a chat application I want to register a new user using php with ejjabered.

<?php
class XMPP_REGISTER_USER
{
public function registerUser($userName, $password) {
$host = '192.168.0.80';
$command = 'register';
$params = array('user' => $userName, 'host' => $host, 'password' => $password);
$response = $this->sendRequest($command, $params);
return $response;
}


public function sendRequest($command, $params) {

$request = xmlrpc_encode_request($command, $params, (array('encoding' => 'utf-8')));

$context = stream_context_create(array('https' => array(
'method' => "POST",
'header' => "User-Agent: XMLRPC::Client mod_xmlrpc\r\n" .
"Content-Type: text/xml\r\n" .
"Content-Length: " . strlen($request),
'content' => $request
)));
// edit RPC server url
$RPC_SERVER = 'https://192.168.0.80:5280/admin/';
$file = file_get_contents($RPC_SERVER , false, $context);
$response = xmlrpc_decode($file);

if (xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
return $response;
}
}



}
$user = new XMPP_REGISTER_USER();
$user->registerUser('[email protected]', 'password');

?>

after running this code the page shows an error “This page isn’t working”.
Please Help me to solve it

Answers: