<Html> <Head> <Title> mobile phone number attribution query </title> </Head> <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. Change it. If (! Isset ($ _ GET ["action"]) { Header ("Location: manage. php? Action = login "); } If ($ _ GET ["action"] = "login "){ ?> <Form action = "manage. php? Action = loginin "method =" POST "> <P> enter the password: </p> <P> <input type = "password" value = "" name = "pwd"> </p> <P> <input type = "submit" value = "Logon"> </p> </Form> <? Php } 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 (); ?> </Div> </Div> <? Php } Elseif ($ _ GET ["action"] = "edit "){ Leftnav (); ?> <Form action = "manage. php? Action = editp "method =" POST "> <P> mobile phone number: <input type = "text" name = "num"> (at least 7 digits) </p> <P> details: <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> <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 ("cannot be blank! "); } } Elseif ("about" ==$ _ GET ["action"]) { Leftnav (); Showabout (); } ?> </Body> </Html>
Index. php <Html> <Head> <Title> mobile phone number attribution query </title> </Head> <Body> <Form action = "index. php? Action = search "method =" POST "> <P> enter the phone number you want to query: <input type = "text" name = "phone"> </p> <P> <input type = "submit" value = ""> </p> </Form> <? Php If (isset ($ _ GET ["action"]) { If ("search" ==$ _ GET ["action"]) { Require ('function. php '); $ Phone = (isset ($ _ POST ["phone"])? $ _ POST ["phone"]: die ("Please return "); Echo "your phone number <font color = red> ". $ phone. "</font> belongs to <font color = red> ". getphone ($ phone ). "</font> "; } } ?> </Body> </Html> Function. php Functions <? Php 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 ("<p> Please <a href = 'Manage. php? Action = login '> log on! </A> </p> "); } Elseif ($ _ SESSION ["flag"]! = True ){ Die ("<p> Please <a href = 'Manage. php? Action = login '> log on! </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 ); $ 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 </p> "; } Echo "total $ counts ";} Function leftnav (){ Check (); ?> <Div> <Div id = "right"> <? Php } Function showabout (){ Echo "<p> mobile phone number attribution query </p> "; } ?> |