Sending the message on XMPP server will require you to register at ejabber server. So here is the code to register a user on ejabbered XMPP server in PHP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php class XMPP_REGISTER_USER { public function registerUser($userName, $password) { $host = 'localhost'; $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('http' => 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 = 'http://IP:4560/RPC2'; $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('user@localhost', 'password'); ?> |