AGI/PHP Getting Variables

I’m trying to pass along variables to a PHP script that runs when a call is placed in a particular context.


exten => s,1,Noop(${Name})
exten => s,1,NoOp(${Dialed})
exten => s,2,Answer()
exten => s,3,AGI(test1.php,${Name},${Dialed})


#!/usr/bin/php -q

$email = "";

$now1 = date("F jS, Y");
$now2 = date("H:i:s");

$to = $email;
$subject = "Variables";
$message = "The Variables used in this call are: $name and $dialed.  The time now is $now1 at $now2.";

$headers = "From:\r\n";
$headers .= "Reply-To:\r\n";
$headers .= "Return-Path:\r\n";



I can simulate the call and have that emailed to me, but I can’t seem to find a good example to tell me how to get the variables into the script.


I think your problem is on the php argument receiving end. Check this out. Good Luck!!

Also just noticed that aside from the priory problem in the dialplan you give. You are also not setting the variables Name and Dialed to anything. So even if your PHP script was parsing them it would be empty.

That worked!.


$name = $argv[1];
$dialed = $argv[2];

The variables are set here:

  $FileHandle = fopen("/tmp/".$FileName, 'w') or die("can't open file $FileName");

  fwrite($FileHandle,"Channel: IAX2/blabla@blabla/$Source_No\n");
  fwrite($FileHandle,"CallerID: Num <$Call_ID>\n");
  fwrite($FileHandle,"Set: Dialed=$Source_No\n");
  fwrite($FileHandle,"Set: Name=$now\n");
  fwrite($FileHandle,"Context: poop\n");
  fwrite($FileHandle,"MaxRetries: 1\n");
  fwrite($FileHandle,"RetryTime: 60\n");
  fwrite($FileHandle,"Priority: 1\n");
  fwrite($FileHandle,"WaitTime: 20\n");
  fwrite($FileHandle,"Extension: s\n");

  if(rename("/tmp/$FileName", "/var/spool/asterisk/outgoing/$FileName")) {