Page 1 of 1

Mobile Operators

Posted: Wed Aug 16, 2006 4:30 am
by kyledeadx
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[b]Mobile Operators[/b]

I'm just wondering?, how php script can detect mobile operator in one country.  

If you are using mobile browser, you can see information in user_agent about mobile information even the operator server.

I have a my code to share

Code: Select all

<?php
//for example: in one country, there's 2 mobile operators
//Given: 673818XXXX - From Telco 1
//           673810XXXX && 673812XXXX-673819XXXX - From Telco 2
/*
Example: You don't know the mobile operator of the country,
by using mobile user_agent, how will detect the mobile operator

*/

$getip = $_SERVER['REMOTE_ADDR'];
$country=Dot2LongIP ($conn,$db,$IPaddr);
$mobilenumber=getmobilenumber();

if((preg_match("/67381/i",$mobilenumber)) && ($country=='BRUNEI DARUSSALAM'))
{
   echo 'telco 1';
}
else
{
   echo 'telco 2';
}

//from this given, how will the script will detect the mobile operator without the given above?

function Dot2LongIP ($conn,$db,$IPaddr)
{
    if ($IPaddr == "") {
        return 0;
    } else {
        $ips = split ("\.",$IPaddr);
		
        return LookUp($conn,$db,($ips[3] + $ips[2] * 256 + $ips[1] * 256 * 256 + $ips[0] * 256 * 256 * 256));
    }
}

function LookUp($conn,$db,$iprange)
{
	$r=mysql_db_query($db,
	"SELECT country_name FROM ip2country WHERE (ip_start_range <= ".$iprange." AND ip_end_range >= ".$iprange.")",$conn) 
	or die(mysql_error());
	$num=mysql_num_rows($r);
	if($num)
	{
		$result=mysql_fetch_row($r);
		$cn=$result[0];
		mysql_free_result($r);
		return $cn;
	}
	else
	{
		return 'unknown country';
	}
}

function LookUp_Currency($conn,$db,$country)
{
	$country=str_replace(" ","%",$country);
	$r=mysql_db_query($db,	
	"SELECT currency FROM iso_currency WHERE country_name LIKE '%".$country."%'",$conn) 
	or die(mysql_error());
	$num=mysql_num_rows($r);
	if($num)
	{
		$result=mysql_fetch_row($r);
		$cn=$result[0];
		mysql_free_result($r);
		return $cn;
	}
	else
	{
		return 'unknown currency';
	}
}

function getmobilenumber(){
 global $_SERVER;
 if(isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID'])){
   //Mostly this Server Vars Attribute is for Nokia
   return trim($_SERVER['HTTP_X_UP_CALLING_LINE_ID']);
 } else if(isset($_SERVER['HTTP_X_HTS_CLID'])) {
   //Mostly this Server Vars Attribute is for Nokia
   return trim($_SERVER['HTTP_X_HTS_CLID']);
 } else if(isset($_SERVER['HTTP_MSISDN'])){
   //Mostly this Server Vars Attribute is for Motorola and Siemens
   return trim($_SERVER['HTTP_MSISDN']);
 }
}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]