Click to Call with PHP-SIP

Posted on: 2009-10-07 | Categories: PHP VoIP

In this tutorial we will show how to implement “click to call” functionality in a web page using PHP-SIP class, free SIP registrar service and Twinkle softphone.

The same principle can be used with any RFC compliant SIP service or your own PBX such as Asterisk or OpenSIPs.

Notice: Please check our new “Click to Call” recommended solution: JavaScript CTI Connector which allows for Computer Telephony Integration (CTI) of customer’s website or application and VoIPstudio Cloud PBX. This integration does not require PHP or any other server side components anymore. Visit VoIPstudio CTI Connector’s official documentation to get all details.


In order to accomplish scenario shown in a diagram below, you will need the following:

  • Basic knowledge of SIP protocol.
  • PHP-SIP class
  • Free SIP account from – this will be our SIP Proxy and sip:user1@sip as shown in the diagram below. Alternatively any SIP compliant SIP service or your own SIP Proxy can be used instead.
  • PHP (version >= 5) enabled web server.
  • Twinkle softphone (on Ubuntu linux can be installed with the following command: apt-get install twinkle) or any other SIP softphone or normal phone. However we provide detailed instructions for Twinkle only.

SIP Flow diagram


  1. User submits a form with calling (sip:user1@sip) and called (sip:user2@sip) parties SIP URIs.
  2. Web Server sends INVITE to sip:user1@sip.
  3. Once INVITE is accepted by user1, web server immediately sends REFER with sip:user2@sip in “Refer-to” header.
  4. Web Server terminates “call” by sending BYE to user1.
  5. As instructed in REFER request sent by a web server, user1 sends INVITE to sip:user2@sip.


1. Create Click to Call web page

Go to your web server root directory and create c2c.php file:


Next we need to download PHP-SIP class from and extract it into your web server root directory, so it looks as shown below:


Now open the web browser and navigate to http://you_web_server/c2c.php which should show a form similar to:



2. Register SIP Phone

For the purpose of this tutorial we assume our test account at is jsmith and softphone used for our test will be Twinkle. However you can use any other SIP proxy and software or normal SIP phone.

Once your SIP account at is set up, start Twinkle, select Edit => User profile... and enter your SIP account details as shown below:


  • enter your username into fields (1) (2) and (5)
  • enter into fields (3) and (4)
  • enter your password into field (6)
  • select SIP server tab (7) and enter into field (8)
  • select SIP protocol tab (9) and deselect Ask user permission for transfer check box


…finally click OK button and if everything went well your Twinkle will display:


3. Testing

Open a web browser and navigate to our “Click to Call” page. Enter into From field, leave default in To field and click Call button. Twinkle should indicate incoming call…


…click Answer and your phone will be automatically connected to which is a public ENUM test service provided by group.

Congratulations! Your Click to Call web page works!


The above illustrates the simplest possible scenario. In a real life applications you may want to use fancy Ajax instead of standard HTML form. Fetch From and/or To SIP URIs from database or do number of even more exciting things.