[asterisk-users] Need help with PHP script to authenticate user from database

Zeeshan Zakaria zishanov at gmail.com
Mon Sep 15 14:46:32 CDT 2008


Hi everyone,

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:

extension.conf
---------------------

[database-lookup]
exten => _.,1,Answer()
exten => _.,n,AGI(lookup.agi)
exten => _.,n,NoOp(${AUTH})
exten => _.,n,Hangup


lookup.agi
---------------

!/usr/bin/php -q
<?php
require '/var/lib/asterisk/agi-bin/phpagi.php';
$agi = new AGI();

$no=preg_replace("#[^0-9]#","",$agi->request[agi_callerid]);

$db = 'db1';
$dbuser = 'user1';
$dbpass = 'password';
$dbhost = 'localhost';

mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db("$db");
$row=mysql_query("select cid from callcheap_users where cid = '$no'");
if (mysql_num_rows($row)==1)
{
        $row=mysql_fetch_array($row);
        if ($row[cid1]) $auth = "YES";
}
        else $auth="NO";
$agi->set_variable("lookupcid", $auth);
?>


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:

    -- Executing AGI("IAX2/4124874318-1", "lookup.agi") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/lookup.agi
    -- AGI Script lookup.agi completed, returning 0
    -- Executing NoOp("IAX2/4124874318-1", "") in new stack
    -- Executing Hangup("IAX2/4124874318-1", "") in new stack

Any help will be highly appreciated.

Thanks

Zeeshan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20080915/5d597637/attachment.htm 


More information about the asterisk-users mailing list