PHP mobile phone number attribution to query program code _php tutorial

Source: Internet
Author: User
Tags ereg
This article summarizes two commonly used mobile phone attribution query program, one is to use API call third-party interface implementation, one is to use our own mobile phone database query and then judge the cell phone number attribution to query.

Let's take a look at a program that calls the third method Web site

The main use of curl implementation, need to open PHP support for curl.

If you are setting up Windows system in your php.ini file, find Php_curl.dll and cancel the previous semicolon comment on the line as follows:
Cancel the comment under the

Extension=php_curl.dll

If you are under Linux, then you need to recompile your PHP, edit, you need to open the compilation parameters, the Configure command to add the "–with-curl" parameter.

Then restart Apache.

code as follows copy code

"!--? php
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 ' phone number format is wrong! ';
} else {
echo $data;
}
}
?

Example Two
This example takes advantage of the phone database, save the file locally and then look up the database to make the difference, but you have to update the database frequently.

The code is as follows Copy Code



Cell phone number attribution to query



Require (' function.php ');
$pwd = "Xiaolin"; Password, please modify
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, Password wrong ~";
}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 "

Log out

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 ("must not be empty!") ");
}
}elseif ("About" ==$_get["action"]) {
LeftNav ();
Showabout ();
}
?>

index.php



Cell phone number attribution to query



if (Isset ($_get["Action"])) {
if ("Search" ==$_get["action"]) {
Require (' function.php ');
$phone = (Isset ($_post["Phone"]))? $_post["Phone"]:d ie ("please return");
echo "The phone number you are inquiring about". $phone. " Belongs to ". Getphone ($phone).";
}
}
?>

function.php function

Session_Start ();

function Update ($num, $info) {
$dbpath = "xiaolin/";
$len =strlen ($num);
if ($len < 7) {
Return "mobile phone number minimum 7 bit Oh";
}
$par = "[0-9]";
for ($i =0; $i < $len; $i + +) {
if (!ereg ($par, substr ($num, $i, 1))) {
Return "mobile phone number can only be digital";
}
}
$sunum =scandir ($dbpath); Get supported mobile number prefixes
Array_splice ($sunum, 0, 1); Cancel the current directory
Array_splice ($sunum, 0, 1); Get rid of the top-level catalogue.
$sub =substr ($num, 0, 3); Get the first three digits of the number
if (In_array ($sub, $sunum)) {
$num 1=ltrim (substr ($num, 3,4), "0");
$search =file ($dbpath. $sub);
$tmp = $search [$num 1];
$search [$num 1]= $num 1. ' = '. $info. ' n ";
$FP 1=fopen ($dbpath. $sub. ' 1 ', ' wb+ ');
for ($i =0; $i <10000; $i + +) {
$phone =str_pad ($i, 4, "0", str_pad_left);
$phoneinfo = "";
$phoneinfo. = $phone. " =";
$phoneinfo = (Isset ($search [$i])? $search [$i]: "";
$phoneinfo. = "n";
Fwrite ($fp 1, $search [$i]);
}
Fclose ($fp 1);
echo "$num has been updated";
}else{
Die ("Temporarily does not support $sub");
}
}
function Getphone ($phone) {
$dbpath = "xiaolin/";
$len =strlen ($phone);
if ($len < 7) {
Return "mobile phone number minimum 7 bit Oh";
}
$par = "[0-9]";
for ($i =0; $i < $len; $i + +) {
if (!ereg ($par, substr ($phone, $i, 1))) {
Return "mobile phone number can only be digital";
}
}
$sunum =scandir ($dbpath); Get supported mobile number prefixes
Array_splice ($sunum, 0, 1); Cancel the current directory
Array_splice ($sunum, 0, 1); Get rid of the top-level catalogue.
$sub =substr ($phone, 0, 3); Get 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); Working with Data
Return (strlen ($result) >1) $result: "No data";
}else{
Return "temporarily does not support $sub";
}
}

function Check () {
if (!isset ($_session["flag"])) {
Die ("

Please login!

");
}elseif ($_session["flag"] = True) {
Die ("

Please login!

");
}
}

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);
$num 1[$tmp [0]]=substr ($line, Strpos ($line, "=") +1,strlen ($line)-strpos ($line, "=")-2);
}
Fclose ($FP);
$flag = 0;
for ($i =0; $i <10000; $i + +) {
$ser =str_pad ($i, 4, "0", str_pad_left);
if (!strlen ($num 1[$ser]) ==0) {
+ + $flag;
}
}
$counts + = $flag;
echo "$nownum: Segment record $flag

";
}
echo "Total $counts";}
function LeftNav () {
Check ();
?>

}
function Showabout () {
echo "

Cell phone number attribution to query


";
}
?>


http://www.bkjia.com/PHPjc/444646.html www.bkjia.com true http://www.bkjia.com/PHPjc/444646.html techarticle This article summarizes two commonly used mobile phone attribution query program, one is to use the API call third-party interface implementation, one is to use our own mobile phone database query and then judge the phone ...

  • Related Article

    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.