Quantcast
Channel: VOIP-info.org Wiki Changes
Viewing all articles
Browse latest Browse all 5767

Asterisk simple php lookup mysql database to set callerid name

$
0
0
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);
?>


Similar contributions

Gigahz' fork of this, with online lookup if local fails
Asterisk simple php lookup up callerid name from Horde Turba

Viewing all articles
Browse latest Browse all 5767

Trending Articles