<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 =&gt; _.,1,Answer()<br>exten =&gt; _.,n,AGI(lookup.agi)<br>exten =&gt; _.,n,NoOp(${AUTH})<br>exten =&gt; _.,n,Hangup<br><br clear="all"><br>lookup.agi<br>---------------<br>
<br>!/usr/bin/php -q<br>&lt;?php<br>require &#39;/var/lib/asterisk/agi-bin/phpagi.php&#39;;<br>$agi = new AGI();<br><br>$no=preg_replace(&quot;#[^0-9]#&quot;,&quot;&quot;,$agi-&gt;request[agi_callerid]);<br><br>$db = &#39;db1&#39;;<br>
$dbuser = &#39;user1&#39;;<br>$dbpass = &#39;password&#39;;<br>$dbhost = &#39;localhost&#39;;<br><br>mysql_connect($dbhost,$dbuser,$dbpass);<br>mysql_select_db(&quot;$db&quot;);<br>$row=mysql_query(&quot;select cid from callcheap_users where cid = &#39;$no&#39;&quot;);<br>
if (mysql_num_rows($row)==1)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $row=mysql_fetch_array($row);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ($row[cid1]) $auth = &quot;YES&quot;;<br>}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else $auth=&quot;NO&quot;;<br>$agi-&gt;set_variable(&quot;lookupcid&quot;, $auth);<br>
?&gt;<br><br><br>As per my understanding, the variable &#39;lookupcid&#39; should have the cid assigned from the database and show it in the NoOp command, but I get the following:<br><br>&nbsp;&nbsp;&nbsp; -- Executing AGI(&quot;IAX2/4124874318-1&quot;, &quot;lookup.agi&quot;) in new stack<br>
&nbsp;&nbsp;&nbsp; -- Launched AGI Script /var/lib/asterisk/agi-bin/lookup.agi<br>&nbsp;&nbsp;&nbsp; -- AGI Script lookup.agi completed, returning 0<br>&nbsp;&nbsp;&nbsp; -- Executing NoOp(&quot;IAX2/4124874318-1&quot;, &quot;&quot;) in new stack<br>&nbsp;&nbsp;&nbsp; -- Executing Hangup(&quot;IAX2/4124874318-1&quot;, &quot;&quot;) in new stack<br>
<br>Any help will be highly appreciated.<br><br>Thanks<br><br>Zeeshan<br>
</div>