Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to XMPP server using PHP

Tags:

php

xmpp

openfire

I have set up an XMPP server, I have created the login form. PHP and HTML. I have not done this before, I want to know how to connect to XMPP server through PHP just like connecting to MySQL using PHP.

like image 625
leeshin Avatar asked Jul 23 '13 04:07

leeshin


1 Answers

<?php 
set_time_limit(0);  // some time connection take while  
require_once 'xmpp-lib/XMPPHP/XMPP.php';  
$host = 'you Host name'; // ex.192.168.2.1  
$port = '5222'; // its defauls xmpp port 
$username = 'name@host' // ex vivek@host 
$pass = 'userpass';  
$conn = new XMPPHP_XMPP(host , $port, $username, $pass, 'xmpphp','yourhost', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);  
try {
         $conn->connect();
         $conn->processUntil('session_start');
         $conn->presence();
         $conn->message('anotherusername@host', 'Hello!');
         $conn->disconnect(); 
} catch(XMPPHP_Exception $e) {
         die($e->getMessage()); 
} 
?>`enter code here`
like image 160
vivek s vamja Avatar answered Sep 29 '22 03:09

vivek s vamja