|
|
wvq111
发表于 2010-8-26 16:23:25
|
显示全部楼层
这个是搜索的代码
<?php
set_time_limit(0);
date_default_timezone_set ('Etc/GMT-8');
include_once('getip.php');//引入获取客户端ip的文件
include_once ('../admin/admin_global.php');//引入数据库类
$nub=$_POST['num'];
$nub=trim($nub);//获取到的从表单传输过来的手机号码
//判断手机号长度,及是否全为数字,如果不是,就中断执行
$length=strlen($nub);
if($length!=11){
echo "<script>alert(\"错误的手机号,手机号码必须是11位的数字\");</script>";
echo "<script>window.location.href='../index.php';</script>";
}
if(!preg_match(('/^\d*$/'),$nub)){
echo "<script>alert(\"错误的手机号,手机号码必须是11位的数字\");</script>";
echo "<script>window.location.href='../index.php';</script>";
}
//当取出号码前3位及前7位========================================
$haoduan=substr($nub,0,7);//手机号的前7位,即手机号段
$file_name_begin=substr($nub,0,3);//手机号的前3位
//获取这个手机号码是否属于22个号段之一,如果不属于,就中断执行=====
$filename = "../data/".$file_name_begin.".txt";
if (!file_exists($filename)) {
echo "<script>alert(\"无该号段的号码!\");</script>";
echo "<script>window.location.href='../index.php';</script>";
}
//获得要插入数据库的个各变量的值==================================
$mobile_nub=$nub;
$search_time=date("Y-m-d H:i:s");
$ary_ip=explode(".",$ip_url);
$ip=$ary_ip[0].".".$ary_ip[1].".".$ary_ip[2].".*";
//$ip=$ary_ip[0].".".$ary_ip[1].".*.*";
$address=$ip_address;
//执行向数据库中插入数据的操作====================================
$sql = "SELECT * FROM mobile_search_".$file_name_begin." where mobile_nub='".$mobile_nub."' and ip='".$ip."'";
$db->query($sql);
$the_number=$db->db_num_rows();
if($the_number==NULL){
$sql = "INSERT INTO `mobile_search_".$file_name_begin."` (`sid`, `mobile_nub`, `search_time`, `ip`, `address`) VALUES (NULL, '$mobile_nub', '$search_time', '$ip', '$address');";
$db->query($sql);
}
else{
for($i=0;$i<$the_number;$i++){
$row=$db->fetch_array();
$my_sid[]=$row["sid"]; //符合同ip,查同号码的数据的sid组成一个数组,其实一般情况这只会有一个数据,但这里用数组的形式,增强通用性
}
$nub_of_my_sid=count($my_sid);
for($i=0;$i<$nub_of_my_sid;$i++){
$sql = "UPDATE mobile_search_".$file_name_begin." SET search_time ='$search_time' , address='$address' WHERE sid =".$my_sid[$i]." LIMIT 1;";
$db->query($sql);
}
}
//向各个号段的ip保存文件添加数据==================================
$str_temp=$search_time.":来自".$address."的用户查询过号码<a href=../nub/".$mobile_nub.".html><font color=red>".$mobile_nub."</font></a>,该用户的IP为:".$ip."@#".$mobile_nub."@#".$ip_url;
$ip_file="../ipdata/".substr($nub,0,5).".txt";
$str_to_write="";
if(file_exists($ip_file)){
$ip_ary=file($ip_file);
$start_line=substr($nub,5,2);
$start_line=intval($start_line);
if($start_line==0){
$start=0;
$end=19;
}
else{
$start=($start_line)*20;
$end=($start_line)*20+19;
}
//判断是否已经存在同一ip查询同一号码的情况存在
$is_same=0;//这个变量用来标识是否存在同一ip查询同一号码的情况
for($i=$start;$i<=$end;$i++){
$my_ary_infor=explode("@#",$ip_ary[$i]);
$my_ary_infor[1]=trim($my_ary_infor[1]);//对应手机号
$my_ary_infor[2]=trim($my_ary_infor[2]);//对应全ip
if($my_ary_infor[1]==$mobile_nub&&$my_ary_infor[2]==$ip_url){
$is_same=1;
$point=$i;//这个变量用来记录相同的是哪一行
break;
}
}
//echo "###########".$is_same;
//echo $point;
if($is_same==0){
//如果在ip数据文件中不存在和这些查询有着同ip查同号码的情况
for($i=0;$i<$start;$i++){
$str_to_write=$str_to_write.$ip_ary[$i];
}
$str_to_write=$str_to_write.$str_temp."\r\n";
for($i=$start;$i<$end;$i++){
$str_to_write=$str_to_write.$ip_ary[$i];
}
$new_start=$end+1;
for($i=$new_start;$i<2000;$i++){
$str_to_write=$str_to_write.$ip_ary[$i];
}
}
else{
//这是一种在ip数据文件中已经存在和这一些查询是同一个ip查同一个号码的情况,那么就执行更新那一条数据的操作,并把那条数据置顶
for($i=0;$i<$start;$i++){
$str_to_write=$str_to_write.$ip_ary[$i];
}
$str_to_write=$str_to_write.$str_temp."\r\n";
for($i=$start;$i<$point;$i++){
$str_to_write=$str_to_write.$ip_ary[$i];
}
for($i=($point+1);$i<=$end;$i++){
$str_to_write=$str_to_write.$ip_ary[$i];
}
$new_start=$end+1;
for($i=$new_start;$i<2000;$i++){
$str_to_write=$str_to_write.$ip_ary[$i];
}
}
}
else
exit;
//echo $str_to_write;
$data_file_path=$ip_file;
$fp=fopen($data_file_path,"w+");
flock($fp,LOCK_EX);
fwrite($fp,$str_to_write);
fclose($fp);
//下面的js跳转到这个号码的页面====================================
?>
<script>window.location.href='../nub/<?php echo $nub; ?>.html';</script> |
|