'talk.google.com', 'port' => 5222, 'username' => 'username', 'password' => 'password', 'proto' => 'xmpphp', 'domain' => 'gmail.com', 'printlog' => true, 'loglevel' => XMPPHP\Log::LEVEL_VERBOSE, ]; // Easy and simple for access to variables with their names extract($conf); $conn = new XMPPHP\XMPP($server, $port, $username, $password, $proto, $domain, $printlog, $loglevel); $conn->autoSubscribe(); try { if (isset($_SESSION['messages'])) { foreach ($_SESSION['messages'] as $message) { echo $message; flush(); } } else { $_SESSION['messages'] = []; } $conn->connect(); $events = ['message', 'presence', 'end_stream', 'session_start', 'vcard']; $payloads = $conn->processUntil($events); foreach ($payloads as $result) { list($event, $data) = $result; if (isset($data)) { extract($data); } switch ($event) { case 'message': if (!$body) { break; } $cmd = explode(' ', $body); $msg = str_repeat('-', 80); $msg .= "\nMessage from: $from\n"; if (isset($subject)) { $msg .= "Subject: $subject\n"; } $msg .= $body . "\n"; $msg .= str_repeat('-', 80); echo "
$msg
"; if (isset($cmd[0])) { if ($cmd[0] == 'quit') { $conn->disconnect(); } if ($cmd[0] == 'break') { $conn->send(''); } } $_SESSION['messages'][] = $msg; flush(); break; case 'presence': echo "Presence: $from [$show] $status\n"; break; case 'session_start': echo "Session start\n"; $conn->getRoster(); $conn->presence('Quasar!'); break; } } } catch (XMPPHP\Exception $e) { die($e->getMessage()); } $conn->saveSession(); echo '';