Search:
     
3CX Phone System for Windows Download the Free Edition

Asterisk simple php lookup mysql database to set callerid name

This script use the AGI to lookup a telephone number in a mysql database created by the user to set the name of the caller

Requires phpagi (phpagi-asmanager.php phpagi-fastagi.php phpagi.php in script folder), php and mysql

extensions.conf:

exten => 100,1,AGI,/path/to/php/script/lookup
exten => 100,n,Set(CALLERID(name)=${lookupcid})
exten => 100,n,Dial(SIP/203,20,t)
exten => 100,n,Hangup

lookup script:

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

$no=preg_replace("#[^0-9]#","",$agi->request[agi_callerid]);//remove any non numeric characters

/*
connect to "asterisk" database in mysql; in this case only 1 table "clients"
column telsearch contains concatenated mobile, home and work numbers
e.g. 0121777887207986238123
script will search for caller number within this field
*/
$db = 'asterisk';
$dbuser = 'xxx';
$dbpass = 'xxx';
$dbhost = 'localhost';

mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db("$db"); //or die("could not open database");
$row=mysql_query("select title,firstname,lastname from clients where telsearch like '%$no%' LIMIT 1");
if (mysql_num_rows($row)==1&&strlen($no)>4){//if found number and number greater than 4 digits to avoid 3 digit internal extensions
        $row=mysql_fetch_array($row);
        if ($row[title]) $name .= $row[title]." ";
        if ($row[firstname]) $name .= $row[firstname]." ";
        if ($row[lastname]) $name .= $row[lastname];
        }
else $name=$agi->request[agi_callerid];//else set calleridname to callerid number
$agi->set_variable("lookupcid", $name);
?>

Created by: johnnyrevell,Last modification on Mon 01 of Sep, 2008 [17:00 UTC]


Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - support@voip-info.org

Page Changes | Comments

 





Search: