php+文本php数据库库搜索问题!一共3个文件:index.php,search.php,gb.dat,

php查询IP地理位置(dat数据库)-纯真IP数据库 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 12时,
看到有人分享了一个,那就分享个经典的利用纯真IP数据库查询吧,相信有很多人都见过甚至用过了这个代码。不过可能不知道,这个代码其实是从一个PECL的C++代码改过来的。
原版(c++)在这
本站也收录了这款软件
代码片段(2)
1.&[代码][PHP]代码&&&&
/*++++++++++++++++++++++++++++++++++++
程序名称:IP解析程序
程序功能:基于QQ的二进制数据库QQWry.Dat
程序作者:strongc
使用方法:
请将文件 QQWry.Dat 置于当前目录中
或者可以用修改
define('__QQWRY__' , dirname(__FILE__).".\QQWry.Dat");
语句自定义QQWry.Dat路径
#实例+++++++++++++++++++++++++++++++
$ip="202.201.48.1";
$QQWry=new QQW
$ifErr=$QQWry-&QQWry($ip);
echo "$QQWry-&Country$QQWry-&Local";
+++++++++++++++++++++++++++++++++++++*/
define('__QQWRY__' , dirname(__FILE__).".\QQWry.Dat");
class QQWry
var $StartIP = 0;
var $EndIP = 0;
var $Country = '';
var $Local = '';
var $CountryFlag = 0; // 标识 Country位置
// 0x01,随后3字节为Country偏移,没有Local
// 0x02,随后3字节为Country偏移,接着是Local
// 其他,Country,Local,Local有类似的压缩。可能多重引用。
var $FirstStartIp = 0;
var $LastStartIp = 0;
var $EndIpOff = 0;
function getStartIp($RecNo)
$offset = $this-&FirstStartIp + $RecNo * 7;
@fseek($this-&fp, $offset, SEEK_SET);
$buf = fread($this-&fp, 7);
$this-&EndIpOff = ord($buf[4]) + (ord($buf[5]) * 256) + (ord($buf[6]) * 256 * 256);
$this-&StartIp = ord($buf[0]) + (ord($buf[1]) * 256) + (ord($buf[2]) * 256 * 256) + (ord($buf[3]) * 256 * 256 * 256);
return $this-&StartIp;
function getEndIp()
@fseek($this-&fp, $this-&EndIpOff, SEEK_SET);
$buf = fread($this-&fp, 5);
$this-&EndIp = ord($buf[0]) + (ord($buf[1]) * 256) + (ord($buf[2]) * 256 * 256) + (ord($buf[3]) * 256 * 256 * 256);
$this-&CountryFlag = ord($buf[4]);
return $this-&EndIp;
function getCountry()
switch($this-&CountryFlag)
$this-&Country = $this-&getFlagStr($this-&EndIpOff + 4);
$this-&Local = (1 == $this-&CountryFlag) ? '' : $this-&getFlagStr($this-&EndIpOff + 8);
$this-&Country = $this-&getFlagStr($this-&EndIpOff + 4);
$this-&Local = $this-&getFlagStr(ftell($this-&fp));
function getFlagStr($offset)
$flag = 0;
@fseek($this-&fp, $offset, SEEK_SET);
$flag = ord(fgetc($this-&fp));
if($flag == 1 || $flag == 2)
$buf = fread($this-&fp, 3);
if($flag == 2)
$this-&CountryFlag = 2;
$this-&EndIpOff = $offset - 4;
$offset = ord($buf[0]) + (ord($buf[1]) * 256) + (ord($buf[2]) * 256 * 256);
if($offset & 12) return '';
@fseek($this-&fp, $offset, SEEK_SET);
return $this-&getStr();
function getStr()
$str = '';
$c = fgetc($this-&fp);
if(ord($c[0]) == 0)
$str .= $c;
function QQwry($dotip = '')
if(!$dotip)
if(ereg("^(127)", $dotip))
$this-&Country = '本地网络';
else if(ereg("^(192)", $dotip))
$this-&Country = '局域网';
$ip = $this-&IpToInt($dotip);
$this-&fp = fopen(__QQWRY__, "rb");
if($this-&fp == NULL)
$szLocal = "OpenFileError";
@fseek($this-&fp, 0, SEEK_SET);
$buf = fread($this-&fp, 8);
$this-&FirstStartIp = ord($buf[0]) + (ord($buf[1]) * 256) + (ord($buf[2]) * 256 * 256) + (ord($buf[3]) * 256 * 256 * 256);
$this-&LastStartIp = ord($buf[4]) + (ord($buf[5]) * 256) + (ord($buf[6]) * 256 * 256) + (ord($buf[7]) * 256 * 256 * 256);
$RecordCount = floor(($this-&LastStartIp - $this-&FirstStartIp) / 7);
if($RecordCount &= 1)
$this-&Country = "FileDataError";
fclose($this-&fp) ;
return 2 ;
$RangB = 0;
$RangE = $RecordC
// Match ...
while($RangB & $RangE - 1)
$RecNo = floor(($RangB + $RangE) / 2);
$this-&getStartIp($RecNo) ;
if($ip == $this-&StartIp)
$RangB = $RecNo;
if($ip & $this-&StartIp) $RangB = $RecNo;
else $RangE = $RecNo;
$this-&getStartIp($RangB);
$this-&getEndIp();
if(($this-&StartIp &= $ip) && ($this-&EndIp &= $ip))
$this-&getCountry();
$this-&Country = '未知';
$this-&Local = '';
fclose($this-&fp);
function IpToInt($Ip)
$array = explode('.', $Ip);
$Int = ($array[0] * 256 * 256 * 256) + ($array[1] * 256 * 256) + ($array[2] * 256) + $array[3];
2.&[代码][PHP]代码&&&&
$ip = "202.201.48.1";
$QQWry = new QQW
$ifErr = $QQWry-&QQWry($ip);
echo $ip . "$QQWry-&Country$QQWry-&Local\n";
202.201.48.1甘肃省兰州市西北师范大学
开源中国-程序员在线工具:
相关的代码(1)
[Ruby/Rails]
呵呵,这个不错,不过缺点是IP地址库得手动更新.有没有第三方接口可以实现的?
2楼:老林 发表于
用了下,感觉还不错。
3楼:Jewel_M 发表于
好东西& 做个记号!
4楼:赖宇旋 发表于
怎么安装呢?能帮我安装一下嘛`!加QQ&&&& !
5楼:I-am-back 发表于
不错呢,刚好能用,省的安装了。
6楼:Take 发表于
&php 5.3 已经不支持&ereg 函数了 !改下!!!
开源从代码分享开始
xyz555的其它代码怎么用SELECT下拉菜单和TEXT文本框从选择数据库搜索数据 - PHP当前位置:& &&&怎么用SELECT下拉菜单和TEXT文本框从选择数据库搜索怎么用SELECT下拉菜单和TEXT文本框从选择数据库搜索数据&&网友分享于:&&浏览:4次如何用SELECT下拉菜单和TEXT文本框从选择数据库搜索数据例如我的下拉列表中学号、姓名、籍贯等选项,我选中“籍贯”,并在后面的文本框中输入“北京”,点击搜索按钮就在数据库中相应的籍贯字段进行匹配,并输出最终的结果。我是用php+mysql,请问我下面的代码有问题吗?总是无法实现功能,显示记录为0条。
HTML页面:
&form&name="search"&action="search.php?action=search"&method="post"&
&select&name="searchoption"&id="searchoption"&
&&&&&&&&&option&value="xh"&selected="selected"&学号&/option&
&&&&&&&&&option&value="xm"&姓名&/option&
&&&&&&&&&option&value="jg"&籍贯&/option&
&&&&&&&&&&&&&&&&&/select&
&input&type="text"&name="keyword"&id="keyword"/&
&&&input&type="submit"&value="搜索"&/&
&&error_reporting(E_ALL&^&E_NOTICE);
&&$dbhost&=&"localhost";
&&$dbuser&=&"root";
&&$dbpassword&=&"";
&&$db&=&mysql_connect($dbhost,&$dbuser,&$dbpassword);
&&mysql_query("SET&NAMES&'UTF8'");
&&mysql_select_db("lxshfile");
&&if(isset($_GET["action"])&&$_GET["action"]=="search"){
&&$searchId&=$_POST["searchoption"];
&&$keyword&=$_POST["keyword"];
&&$sqltext&=&"select&*&from&lxsh&where&'$searchId'&like&'%$keyword%'";
&&$result&=&mysql_query($sqltext);
&&$row&=&mysql_numrows($result);
&&if($keyword==""){
echo"&p&align='center'&&strong&请输入关键词!&/strong&&/p&";
//若没有输入关键词,则结束程序
&&echo("&strong&&br/&搜索结果:共有".$row."条记录&/strong&&/br&");&
&&echo("&table&width='100%'&border='1'&bordercolor='#0066CC'&&tr&&td&align='center'&&strong&学号&/strong&&/td&");
&&echo("&td&align='center'&&strong&姓名&/strong&&/td&");
&&echo("&td&align='center'&&strong&籍贯&/strong&&/td&&/tr&");
&&while&($table&=&mysql_fetch_array($result))//输出数据查询数据!
&&echo("&tr&&td&align='center'&".$table['xh']."&/td&");
&&echo("&td&align='center'&".$table['xm']."&/td&");
&&echo("&td&align='center'&".$table['jg']."&/td&&/tr&");
&&echo("&/table&");&
?&------解决方案--------------------'$searchId'&&=&`$searchId`&&或者干脆就什么都别加。
mysql_num_rows------解决方案--------------------$sqltext&=&"select&*&from&lxsh&where&'$searchId'&like&'%$keyword%'";
把这一句改成:
$sqltext&=&"select&*&from&lxsh&where&$searchId&like&'%$keyword%'";
echo&$//可以打印出来看一下
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有& & 我用一个留言本程序作为例子,阐述 PHP 实现对文本 数据库 的数据显示、加入、修改、删除、查询五大基本操作的方法。 此文本 数据库 共有字段10个:客户IP、发言时间、客户名、客户EMAIL、客户主页地址、留言表情图片名、客户 QQ 、客户形象图片、留言内容、&nb……
声明:该文章系网友上传分享,此内容仅代表网友个人经验或观点,不代表本网站立场和观点;若未进行原创声明,则表明该文章系转载自互联网;若该文章内容涉嫌侵权,请及时向
论文写作技巧
上一篇:下一篇:
相关经验教程PHP对文本文件的搜索
PHP对文本文件的搜索
&&&&――此文章摘自
&&&&本节将介绍一个对文件夹下全部文本文件进行搜索的方法。PHP程序通过对文件夹下全部文件的读取来检测文件是否包含搜索的内容。具体代码如下所示。&&&&&?php &&&&//获得关键词 &&&&$colname_rs = $_GET['key']; &&&&$result = explode(',',$_GET['key']); &&&&$file_result = array();&&&&&&&&&&&&&&&&&&&&&&&& //初始化数组 &&&&$dir = "files/";&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //定义路径 &&&&$dir_res = opendir($dir);&&&&&&&&&&&&&&&&&&&&&& //打开目录 &&&&while($filen=readdir($dir_res))&&&&&&&&&&&&&&&& //循环读取目录中的文件 &&&&{ &&&&&&& if($filen == '.' || $filen == '..')&&&& //将当前目录和父目录过滤掉 &&&&&&& { &&&&&&&&&&& &&&&&&& } &&&&&&& $file = fopen($dir.$filen, "r");&&&&&&&&&&& //打开文件 &&&&&&& $filesize = filesize($dir.$filen);&&&&&&&&& //获取文件长度 &&&&&&& $filecont = fread($file, $filesize);&&&&&&& //获取文件的全部内容 &&&&&&& fclose($file);&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //关闭文件 &&&&&&& //循环搜索文件 &&&&&&& for($i=0,$j=0;$i&count($result);$i++) &&&&&&& { &&&&&&&&&&&& if($result[$i]!='' && strstr($filecont, $result[$i])) &&&&&&&&&&&&&&&&&&//如果文件找到,则将文件名保存到数组中 &&&&&&&&&&& { &&&&&&&&&&&&&&& $file_result[$j] = $ &&&&&&&&&&&&&&& $j++; &&&&&&&&&&& } &&&&&&& } &&&&} &&&&closedir($dir_res);&&&&&&&&&&&&&&&&&&&&&&&&&&&& //关闭目录 &&&&?& &&&&&html& &&&&&head& &&&&&title&Search&/title& &&&&&meta http-equiv="Content-Type" content="text/ charset=gb2312"& &&&&&/head& &&&&&body& &&&&&form name="form1" method="get" action="?"& &&&&& &div align="center"&请输入要搜索的关键词: &&&&&&& &input name="key" type="text" size="64" value="&?php echo $_GET['key'] ?&"& &&&&&&& &input type="submit" value="Submit"& &&&&& &/div& &&&&&/form& &&&&&p align="center"&&B&当前关键词: &&&&&?php &&&&for($i=0;$i&count($result);$i++)&&&&&&&&&&&&&&& //获得所有的关键词 &&&&{ &&&&& echo $result[$i]." "; &&&&} &&&&?&&/B&&/p& &&&&&p&&hr&&/p& &&&&&?php for($j=0;$j&count($file_result);$j++) { ?& &&&&&p&* &a href="&?php echo $dir.$file_result[$j]; ?&"&&?php echo $file_result [$j]; ?&&/a&&/p& &&&&&?php } ?& &&&&&/body& &&&&&/html&
&&&&运行结果如图36-3所示。
图36-3& 搜索文本文件
H3C认证Java认证Oracle认证
基础英语软考英语项目管理英语职场英语
.NETPowerBuilderWeb开发游戏开发Perl
二级模拟试题一级模拟试题一级考试经验四级考试资料
软件测试软件外包系统分析与建模敏捷开发
法律法规历年试题软考英语网络管理员系统架构设计师信息系统监理师
高级通信工程师考试大纲设备环境综合能力
路由技术网络存储无线网络网络设备
CPMP考试prince2认证项目范围管理项目配置管理项目管理案例项目经理项目干系人管理
职称考试题目
招生信息考研政治
网络安全安全设置工具使用手机安全
生物识别传感器物联网传输层物联网前沿技术物联网案例分析
Java核心技术J2ME教程
Linux系统管理Linux编程Linux安全AIX教程
Windows系统管理Windows教程Windows网络管理Windows故障
数据库开发Sybase数据库Informix数据库
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&

我要回帖

更多关于 php数据库 的文章

 

随机推荐