Search code examples
phpxmppopenfire

How to connect with OpenFire(xmpp) using RESTAPI plugin And PHP


I am using OpenFire to manage my xmpp server I want to add new users using a PHP, So I have installed RESETAPI Plugin to OpenFire to administrate with http request. I am using gidkom Project also. But getting a error

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\IM\registration.php on line 12

My code for registration.php is:

<?php 
if(isset($_POST["User_Name"]) && isset($_POST["Name"]) )
{
$User_ID = $_POST["User_Name"];
$User_Name = $_POST["Name"];
$User_Email = $_POST["Email"];
include "Gidkom/OpenFireRestApi/OpenFireRestApi.php";
// Create the OpenfireUserservice object
$api = new Gidkom\OpenFireRestApi

// Set the required config parameters
$api->secret = "my keys";
$api->host = "domain.my.org";
$api->port = "9090";  // default 9090

// Optional parameters (showing default values)

$api->useSSL = false;
$api->plugin = "/plugins/restapi/v1";  // plugin 

// Add a new user to OpenFire and add to a group
$result = $api->addUser($User_ID, 'Password', $User_Name, $User_Email, array('welcome'));

// Check result if command is succesful
if($result['status']) {
    // Display result, and check if it's an error or correct response
    echo 'Success: ';
    echo $result['message'];
} else {
    // Something went wrong, probably connection issues
    echo 'Error: ';
    echo $result['message'];
}






//Add to roster
$api->addToRoster('Administrator', 'admin');

}
else
{
echo 'Error: Something went wrong..... <a href="registration.html">please go back</a> ';

}

I want the page to add a new new user in the openfire and add admin to his roster. Thanks !!!!


Solution

  • The errors were caused because of an outdated version of PHP, YPdating PHP to latest version fixed it...