A simple php script to add user to Openfire databese

Im trying to integrate Openfire with an email aplication, and i need a script ( php ) to add new users directly to Openfire database.

I made this script

<?php

$cnt = mysql_connect(“localhost”,“root”,“pass”);

if (!$cnt)

{

die('Nu se poate conecta la baza de date CANT CONNECT : ’ . mysql_error());

}

$pass = $_POST;

$encryptedPassword = md5($pass);

mysql_select_db(“im”, $cnt);

mysql_query(“insert into jiveUser(username, encryptedPassword, email, name) values(’$_POST[username]’, ‘$encryptedPassword’ , ‘$_POST[email]’, ‘$_POST[name]’)”);

echo "Introdus in baza de date ! DONE ";

mysql_close();

?>

After ive added some new users , whom i saw them in phpmyadmin, i cant login with those users via Spark

After that i went to admin interface to see if, when i click Users/Grups new users added by this scripts are shown.

They arent, but they are counted , i meen i see 20 users but system tell me that i have 23 users . those 3 added by this script are not shown

Any ideea where its my mistake ?

Thank You and Best Regards

It’s not a good idea to write directly to a DB. Openfire is using caches to store user data (RAM), so it’s much quicker than accessing DB all the time. That’s why (though i’m not an expert of this area) you arent seeing new users. You’ll probably see them after server restart. Or you can minimize cache expiration time (must be somethere in the forums or docs). Or you can use User Service plugin, which will use Openfire API instead of direct DB access. http://www.igniterealtime.org/projects/openfire/plugins.jsp

Thanks for the help. After restart the same problem.

Openfire do count the users i have in sistem, but only shows old users not the new ones that i have added

Phpmyadmin shos the new users in jiveUser table

I want to to this scrip to integrate with a custom email messaging service , and when new user sign up also to signup for instant messenger

luxmail, have a look here:

http://www.igniterealtime.org/projects/openfire/plugins/userservice/readme.html

you can simply use this service to add users… and if you want to use it with php …

in php just build the correct userservice url, then use CURL …

or fopen …

for example, here i will create a user called luxmail:

$f = fopen(“http://example.com:9090/plugins/userService/userservice?type=add&secret=bigsecre t&username=luxmail&password=parola_ta&name=franz&email=admin@luxmail.comsecret&username=luxmail&password=parola_ta&name=franz&email=admin@luxmail.com”);

$response = fread($f, 1024);

if (ereg(‘OK’, $response)) {

echo ‘userul a fost introdus cu succes’;

} else {

echo ‘a aparut o eroare la introducerea userului’;

}

fclose($f);

Thank you, ive solved the problem with cURL. Many thanks

is there any way to add use with php and enryption because i think it’s a insecure way to add users.can i encrpt passwords by myself?

Hi, Can you please share your script?