# \[SOLVED\] Trying to pass Asterisk variables to a PHP script

**URL:** <https://community.asterisk.org/t/solved-trying-to-pass-asterisk-variables-to-a-php-script/18161>\
**Category:** Asterisk Support\
**Created:** [December 14, 2007, 1:48pm UTC](https://community.asterisk.org/t/solved-trying-to-pass-asterisk-variables-to-a-php-script/18161 "2007-12-14T13:48:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ste.richards](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/ste.richards/32/973_2.png) [@ste.richards](https://community.asterisk.org/u/ste.richards)\
**Post date:** [December 14, 2007, 1:48pm UTC](https://community.asterisk.org/t/solved-trying-to-pass-asterisk-variables-to-a-php-script/18161/1 "2007-12-14T13:48:56Z")

</div>

I’m only 3 days old to Asterisk and I’m having great difficulty passing Asterisk variables (EG - callerid) to a PHP script. I’m trying to a very basic exercise of dialing a VoIP number and having a PHP script run which inserts the caller ID into a MySQL database.

I have read quite a few tutorials but none seem to give a straight example of passing a variable to a PHP script and being able to read that variable in the PHP script.

So here’s what I’m using:

extensions.conf:  
exten =\> 101,1,Answer()  
exten =\> 101,2,AGI(test.php|${agi\_calleridname})  
exten =\> 101,4,Hangup()

test.php:  
#!/usr/bin/php -q

\<?php $fh = fopen("test.txt", "a+"); foreach($\_REQUEST as $key =\> $val) fwrite($fh, "Key: ".$key." Val: ".$val."\n\n") ?\>

The script is a+x chmodded and if I execute the script from a bash shell manually the script will insert, if I manually put an array element into $\_POST or $\_GET.

I have ran ‘asterisk -cr’ from the command line and I can’t see any errors regarding the AGI.

Any help welcome,

---

<div class="post-metadata">

**Author:** ![mnapuran](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/mnapuran/32/120_2.png) [@mnapuran](https://community.asterisk.org/u/mnapuran)\
**Post date:** [May 6, 2008, 6:08pm UTC](https://community.asterisk.org/t/solved-trying-to-pass-asterisk-variables-to-a-php-script/18161/2 "2008-05-06T18:08:24Z")

</div>

So what was the fix?! ❓

---

<div class="post-metadata">

**Author:** ![chrisalane](https://avatars.discourse-cdn.com/v4/letter/c/aca169/32.png) [@chrisalane](https://community.asterisk.org/u/chrisalane)\
**Post date:** [May 18, 2008, 8:36pm UTC](https://community.asterisk.org/t/solved-trying-to-pass-asterisk-variables-to-a-php-script/18161/3 "2008-05-18T20:36:54Z")

</div>

He doesnt specify what version he is using, but i assume his problem is:

$agi\_calleridname which should be

${CALLERID(name)} or ${CALLERID(num)} depending on your needs.
