Sunday, October 18, 2009

SIP applications ...in PHP

With basic SIP knowledge and a few lines of code any PHP developer can develop SIP applications. PHP-SIP is a PHP implementation of a SIP UA that allows to implement things like click-to-call, message waiting indications or SIMPLE based instant messages.

On Level 7 Systems' blog they show how to implement click-to-call functionality
triggered from a web page - in a relatively simple PHP script.


$api = new PhpSIP();

$api->setDebug(true);

$api->addHeader('Subject: click2call');
$api->setMethod('INVITE');
$api->setFrom('sip:c2c@'.$api->getSrcIp());
$api->setUri($from);

$res = $api->send();

if ($res == 200)
{
$api->setMethod('REFER');
$api->addHeader('Refer-to: '.$to);
$api->addHeader('Referred-By: sip:c2c@'.$api->getSrcIp());
$api->send();

$api->setMethod('BYE');
$api->send();

$api->listen('NOTIFY');
$api->reply(481,'Call Leg/Transaction Does Not Exist');
}



Check it out the full application here:
Click to Call with PHP-SIP

No comments: