PHP mobile phone number home location query program code _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Tags ereg
PHP mobile phone number, local query program code. This article summarizes two commonly used mobile phone home location query programs. one is to use APIs to call third-party interfaces, one is to use our own mobile phone database to query and then judge the mobile phone. This article summarizes two common mobile phone home location query programs. The other is to use APIs to call third-party interfaces, one is to use our own mobile phone database to query and then judge the mobile phone number in the local query.

First, let's look at a program that calls the third method website.

It is mainly implemented using curl and requires php support for curl.

If you are using a windows system in your php. ini file settings, find php_curl.dll and cancel the semicolon comment, as shown below:
// Cancel the comment

Extension = php_curl.dll

If you are in Linux, you need to recompile your PHP. during editing, you need to open the compilation parameters and add the "-with-curl" parameter to the configure command.

Restart apache

The code is as follows:

Header ("Content-Type: text/html; charset = utf-8 ");
If (isset ($ _ GET ['Number']) {
$ Url = 'http: // webservice.webxml.com.cn/webservices/mobilecodews.asmx/getmobilecodeinfo ';
$ Number = $ _ GET ['Number'];
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_POST, true );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, "mobileCode = {$ number} & userId = ");
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true );
$ Data = curl_exec ($ ch );
Curl_close ($ ch );
$ Data = simplexml_load_string ($ data );
If (strpos ($ data, 'http ://')){
Echo 'mobile phone number format error! ';
} Else {
Echo $ data;
}
}
?>

Instance 2
This instance uses the mobile phone database to store files locally and then find the database. However, you must update the database frequently.

The code is as follows:



Mobile phone number attribution query



Require ('function. php ');
$ Pwd = "xiaolin"; // password. change it.
If (! Isset ($ _ GET ["action"]) {
Header ("Location: manage. php? Action = login ");

}
If ($ _ GET ["action"] = "login "){

?>

} Elseif ($ _ GET ["action"] = "loginin "){
$ Repwd = $ _ POST ["pwd"];
If ($ repwd! = $ Pwd ){
Echo "Sorry, incorrect password ~! ";
} Else {
$ _ SESSION ["flag"] = true;
Leftnav ();
}

} Elseif ($ _ GET ["action"] = "info "){
Leftnav ();
Getinfo ();
?>



} Elseif ($ _ GET ["action"] = "edit "){
Leftnav ();
?>



} Elseif ($ _ GET ["action"] = "loginout "){
If (isset ($ _ SESSION ["flag"]) {
Unset ($ _ SESSION ["flag"]);
Session_destroy ();
}
Echo"

Logout

Return

";


} Elseif ($ _ GET ["action"] = "editp "){
Leftnav ();
$ Num = $ _ POST ["num"];
$ Info = $ _ POST ['info'];
If (! Empty ($ num )&&! Empty ($ info) & strlen ($ num) >=7 ){
Update ($ num, $ info );
} Else {
Die ("cannot be blank! ");
}
} Elseif ("about" ==$ _ GET ["action"]) {
Leftnav ();
Showabout ();
}
?>

Index. php



Mobile phone number attribution query



If (isset ($ _ GET ["action"]) {
If ("search" ==$ _ GET ["action"]) {
Require ('function. php ');
$ Phone = (isset ($ _ POST ["phone"])? $ _ POST ["phone"]: die ("Please return ");
Echo "your phone number". $ phone. "belongs to". getphone ($ phone )."";
}
}
?>

Function. php functions

Session_start ();

Function update ($ num, $ info ){
$ Dbpath = "xiaolin /";
$ Len = strlen ($ num );
If ($ len <7 ){
Return "the minimum mobile phone number is 7 characters ";
}
$ Par = "[0-9]";
For ($ I = 0; $ I <$ len; $ I ++ ){
If (! Ereg ($ par, substr ($ num, $ I, 1 ))){
Return "the mobile phone number can only be a number ";
}
}
$ Sunum = scandir ($ dbpath); // Get the supported mobile phone number prefix
Array_splice ($ sunum,); // cancel the current directory
Array_splice ($ sunum,); // remove the upper-level Directory
$ Sub = substr ($ num,); // obtain the first three digits of the number.
If (in_array ($ sub, $ sunum )){
$ Num1 = ltrim (substr ($ num, 3, 4), "0 ");
$ Search = file ($ dbpath. $ sub );
$ Tmp = $ search [$ num1];
$ Search [$ num1] = $ num1. '='. $ info. "n ";
$ Fp1 = fopen ($ dbpath. $ sub. '1', 'WB + ');
For ($ I = 0; I I <10000; $ I ++ ){
// $ Phone = str_pad ($ I, 4, "0", STR_PAD_LEFT );
// $ Phoneinfo = "";
// $ Phoneinfo. = $ phone. "= ";
// $ Phoneinfo = (isset ($ search [$ I])? $ Search [$ I]: "";
// $ Phoneinfo. = "n ";
Fwrite ($ fp1, $ search [$ I]);
}
Fclose ($ fp1 );
Echo "$ num updated ";
} Else {
Die ("$ sub is not supported currently ");
}
}
Function getphone ($ phone ){
$ Dbpath = "xiaolin /";
$ Len = strlen ($ phone );
If ($ len <7 ){
Return "the minimum mobile phone number is 7 characters ";
}
$ Par = "[0-9]";
For ($ I = 0; $ I <$ len; $ I ++ ){
If (! Ereg ($ par, substr ($ phone, $ I, 1 ))){
Return "the mobile phone number can only be a number ";
}
}
$ Sunum = scandir ($ dbpath); // Get the supported mobile phone number prefix
Array_splice ($ sunum,); // cancel the current directory
Array_splice ($ sunum,); // remove the upper-level Directory
$ Sub = substr ($ phone,); // obtain the first three digits of the number.
If (in_array ($ sub, $ sunum )){
$ Num = ltrim (substr ($ phone, 3,4), "0 ");
$ Search = file ($ dbpath. $ sub );
$ Tmp = $ search [$ num];
$ Result = substr ($ tmp, strpos ($ tmp, "=") + 1, strlen ($ tmp)-strpos ($ tmp, "=")-2 ); // process data
Return (strlen ($ result)> 1 )? $ Result: "No data ";
} Else {
Return "$ sub" is not supported Currently ";
}
}

Function check (){
If (! Isset ($ _ SESSION ["flag"]) {
Die ("

Please log on!

");
} Elseif ($ _ SESSION ["flag"]! = True ){
Die ("

Please log on!

");
}
}

Function getinfo (){
Check ();
$ Nums = array ("130", "131", "132", "133", "134", "135", "136", "137 ", "138", "139", "150", "151", "153", "155", "156", "157", "158 ", "159 ");
$ Counts = "";
For ($ j = 0; $ j $ Id = $ j;
If ($ id> = count ($ nums) {die ("OVER ");}
$ Nownum = $ nums [$ id]; // The current number segment
$ Dbpath = "xiaolin /";
$ Fp = fopen ("xiaolin/$ nownum", 'r ');
While (! Feof ($ fp )){
$ Line = fgets ($ fp );
$ Tmp = explode ("=", $ line );
$ Num1 [$ tmp [0] = substr ($ line, strpos ($ line, "=") + 1, strlen ($ line)-strpos ($ line, "=")-2 );
}
Fclose ($ fp );
$ Flag = 0;
For ($ I = 0; I I <10000; $ I ++ ){
$ Ser = str_pad ($ I, 4, "0", STR_PAD_LEFT );
If (! Strlen ($ num1 [$ ser]) = 0 ){
++ $ Flag;
}
}
$ Counts + = $ flag;
Echo "$ nownum: Segment record $ flag

";
}
Echo "total $ counts ";}
Function leftnav (){
Check ();
?>

}
Function showabout (){
Echo"

Mobile phone number attribution query


";
}
?>


...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.