Send message to XMPP server in php

If you are creating any chat application or wanted to send real time messages or data you simplest possible solution is XMPP. Here I'm writing the for sending the messages on XMPP server in PHP. I'm using ejabbered server here. so both sender and receiver have to register themselves over the ejabbered server before sending the messages to each other. Here is the code to register the user on ejabbered XMPP server.

Here is the PHP code to send the messages.


Share This:

XMPP strophe.js demo code

Share This:

Add or remove a user from a room/group using strophe.js

addUser: function (Jid, name, groups) { if (!Chat.userExists(Jid)) { var groups = (groups) ? groups : ''; Chat.connection.roster.add(Jid, name, groups, function (status) { Chat.Roster.push({'jid': Jid, 'name': name, subscription: '' //NOTE:MIGHT BE ERROR PRONE TO NOT DECLARE SUBSCRIPTION... }); Chat.log("User Added to roster: " + name, status, Chat.Roster); }); Chat.log("Added user: " + Jid); } else Chat.log("Error adding new User"); },

//remove user from your roster removeUser: function (Jid) { if (Chat.userExists(Jid)) { //Chat.connection.roster.get(); var iq = $iq({type: 'set'}).c('query', {xmlns: Strophe.NS.ROSTER}).c('item', {jid: Jid, subscription: "remove"}); Chat.connection.sendIQ(iq, function (status) { Chat.log("Removed: " + Jid, status); }); for (var i = Chat.Roster.length - 1; i >= 0; i--) { if (Chat.Roster[i].jid === Jid) { Chat.Roster.splice(i, 1); Chat.log(Chat.Roster); } } } else Chat.log("Error removing user"); },

Share This: