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.

extensions.conf:

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

test1.php

#!/usr/bin/php -q
<?


$email = "xxxxxxx@gmail.com";

$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: xxxxxx@xxxxxxx.biz\r\n";
$headers .= "Reply-To: xxxxxx@xxxxxxx.biz\r\n";
$headers .= "Return-Path: xxxxxxxx@xxxxxxx.net\r\n";

mail($to,$subject,$message,$headers);

?>

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.

Thanks.

I think your problem is on the php argument receiving end. Check this out. php.net/manual/en/reserved.variables.argv.php 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!.


var_dump($argv);


$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");
  fclose($FileHandle);

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

Thanks!