<div dir="ltr">Hi everyone,<br><br>I am trying to write a basic AGI script in PHP to authenticate a user from database. So far I have no luck. Need help. Maybe somebody can share their code. Here is what I have:<br><br>extension.conf<br>
---------------------<br><br>[database-lookup]<br>exten => _.,1,Answer()<br>exten => _.,n,AGI(lookup.agi)<br>exten => _.,n,NoOp(${AUTH})<br>exten => _.,n,Hangup<br><br clear="all"><br>lookup.agi<br>---------------<br>
<br>!/usr/bin/php -q<br><?php<br>require '/var/lib/asterisk/agi-bin/phpagi.php';<br>$agi = new AGI();<br><br>$no=preg_replace("#[^0-9]#","",$agi->request[agi_callerid]);<br><br>$db = 'db1';<br>
$dbuser = 'user1';<br>$dbpass = 'password';<br>$dbhost = 'localhost';<br><br>mysql_connect($dbhost,$dbuser,$dbpass);<br>mysql_select_db("$db");<br>$row=mysql_query("select cid from callcheap_users where cid = '$no'");<br>
if (mysql_num_rows($row)==1)<br>{<br> $row=mysql_fetch_array($row);<br> if ($row[cid1]) $auth = "YES";<br>}<br> else $auth="NO";<br>$agi->set_variable("lookupcid", $auth);<br>
?><br><br><br>As per my understanding, the variable 'lookupcid' should have the cid assigned from the database and show it in the NoOp command, but I get the following:<br><br> -- Executing AGI("IAX2/4124874318-1", "lookup.agi") in new stack<br>
-- Launched AGI Script /var/lib/asterisk/agi-bin/lookup.agi<br> -- AGI Script lookup.agi completed, returning 0<br> -- Executing NoOp("IAX2/4124874318-1", "") in new stack<br> -- Executing Hangup("IAX2/4124874318-1", "") in new stack<br>
<br>Any help will be highly appreciated.<br><br>Thanks<br><br>Zeeshan<br>
</div>