PHP Phone number attribution to the query program code

Source: Internet
Author: User
Tags curl ereg require strlen

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

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

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

Extension=php_curl.dll

If you are under Linux, then you need to recompile your PHP, when editing, you need to open the compile parameters and add "–with-curl" parameters to the Configure command.

and restart Apache.

The code is 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 is malformed! '
} else {
echo $data;
}
}

<form action= "mobile.php" method= "Get"
Mobile: <input type= "text" name= "number"/> &L T;input type= "Submit" value= "commit"/>
</form>

Example Two
This example uses the mobile database, saves the file locally and then finds the database, but you need to update the database frequently.

The code is as follows Copy Code

<title> mobile phone number attribution to the query </title>
<style type= "Text/css" >
#main {
height:100%;
}
#left {
Float:left;
height:100%;
width:10%;
Float:left;
}
#right {
Float:left;
height:100%;
width:100$;
}
</style>
<body>
<?php
Require (' function.php ');
$pwd = "Xiaolin"; Password, please modify
if (!isset ($_get["action")) {
Header ("Location:manage.php?action=login");

}
if ($_get["action"]== "login") {

?>
<form action= "Manage.php?action=loginin" method= "POST" >
<p> Please enter the password:</p>
<p><input type= "Password" value= "name=" pwd "></p>
<p><input type= "Submit" value= "Login" ></p>
</form>
<?php
}elseif ($_get["action"]== "Loginin") {
$repwd =$_post["pwd"];
if ($repwd!= $pwd) {
echo "Sorry, password error ~!";
}else {
$_session["Flag"]=true;
LeftNav ();
}

}elseif ($_get["action"]== "info") {
LeftNav ();
GetInfo ();
?>
</div>
</div>
<?php
}elseif ($_get["Action"]== "edit") {
LeftNav ();
?>
<form action= "MANAGE.PHP?ACTION=EDITP" method= "POST" >
<p> Mobile Number: <input type= "text" name= "num" > (at least 7 digits) </p>
<p> Detailed information: <input type= "text" name= "info" ></p>
<input type= "Submit" value= "Update" >
</form>

<?php

}elseif ($_get["action"]== "Loginout") {
if (Isset ($_session["flag"])) {
unset ($_session["flag"]);
Session_destroy ();
}
echo "<p><a> logout </a></p><p><a href= ' manage.php ' > Return </a></p>";


}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 ();
}
?>
</body>

index.php

<title> mobile phone number attribution to the query </title>
<body>
<form action= "Index.php?action=search" method= "POST" >
<p> Please input the mobile number you want to inquire: <input type= "text" name= "Phone" ></p>
<p><input type= "Submit" value= "Search mobile number Attribution" ></p></p>
</form>
<?php
if (Isset ($_get["action")) {
if ("Search" ==$_get["action"]) {
Require (' function.php ');
$phone = (Isset ($_post["Phone"])? $_post["Phone"]:d ie ("please return");
echo "The cell phone number you queried <font color=red>". $phone. " </font> belongs to <font color=red> ". Getphone ($phone)." </font> ";
}
}
?>
</body>

function.php function

<?php

Session_Start ();

function Update ($num, $info) {
$dbpath = "xiaolin/";
$len =strlen ($num);
if ($len < 7) {
Return "mobile phone number of the lowest 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 a number";
}
}
$sunum =scandir ($dbpath); Get supported phone number prefix
Array_splice ($sunum, 0, 1); Cancel the current directory
Array_splice ($sunum, 0, 1); Get rid of the upper 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 updated";
}else{
Die ("Temporarily does not support $sub");
}
}
function Getphone ($phone) {
$dbpath = "xiaolin/";
$len =strlen ($phone);
if ($len < 7) {
Return "mobile phone number of the lowest 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 a number";
}
}
$sunum =scandir ($dbpath); Get supported phone number prefix
Array_splice ($sunum, 0, 1); Cancel the current directory
Array_splice ($sunum, 0, 1); Get rid of the upper 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 ("<p> please <a href= ' manage.php?action=login ' > Login!</a></p>");
}elseif ($_session["flag"]!= true) {
Die ("<p> please <a href= ' manage.php?action=login ' > Login!</a></p>");
}
}

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 <count ($nums); $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</p>";
}
echo "Total $counts";}
function LeftNav () {
Check ();
?>
<div>

<div id= "Right" >

<?php
}
function Showabout () {
echo <p> mobile phone number attribution to the query </p>
";
}
?>

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.