Asterisk can be used to originate calls from a web page. Asterisk Manager Interface (AMI) is used for this purpose. AMI allows external programs to control asterisk.


For doing this , you should have

  • A working asterisk server
  • A SIP termination provider for sending calls out
  • A webpage for entering phone numbers


You have to first create a manager user in asterisk.  This is created inside /etc/asterisk/manager.conf file

Move the existing manager file using the command

mv /etc/asterisk/manager.conf /etc/asterisk/manager-bk.conf


Create a new manager file

touch /etc/asterisk/manager.conf


Add the below contents to the newly created manager.conf file



enabled = yes

port = 5038

bindaddr =



secret = password



read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan

write = system,call,agent,user,config,command,reporting,originate,message



Now, create a php script,  and the following contents to it. Your webpage will be posting numbers to this php script. It then connect to asterisk using AMI, send call to the entered number and connect it to an extension 1000 in the system.



$host = “”;

$user = “clicktocall”;

$secret = “password”;

$context = “dial”;

$waitTime = “30”;

$priority = “1”;

$number = $_POST[“number”];


$oSocket = fsockopen($host, 5038, $errnum, $errdesc) or die(“Connection to host failed”);

fputs($oSocket, “Action: loginrn”);

fputs($oSocket, “Events: offrn”);

fputs($oSocket, “Username: $userrn”);

fputs($oSocket, “Secret: $secretrnrn”);


fputs($oSocket, “Action: originatern”);

fputs($oSocket, “Channel: SIP/didforsale/$numberrn”);

fputs($oSocket, “WaitTime: $waitTimern”);

fputs($oSocket, “exten: 1000rn”);

fputs($oSocket, “Context: $contextrn”);

fputs($oSocket, “Async: Truern”);

fputs($oSocket, “Priority: $priorityrnrn”);

fputs($oSocket, “Action: Logoffrnrn”);





Create a dialplan entry now to send calls to extension 1000 in the system when the number answers. Open your /etc/asterisk/extensions.conf file and add the following to it



exten => 1000,1,Dial(SIP/1000)

Same => n,Hangup

Now create your webpage, add a number field in the webpage to enter the number. When some one enters a number in this field, post it to the php script we just created.

That is it and now some one enters a number in the webpage, he will get a call immediately and when he answers the call, extension 1000 will rings and they will get connected.

Share This