想在PHP程序加入base64_decode,防止别人采集,相应的位置不知道加在哪里
图片上半部份是  ?id=数字。 好采集。
下半部分是通过是我想要的效果,
不知应该加在哪里<?php
$title = '新华字典'; //查询名称,不必修改
$is_cache = 1; //缓存设置 1打开 0关闭$dbhost = xxx.com'; //MYSQL服务器【需配置】
$dbname = 'acz'; //数据库名称【需配置】
$dbuser = 'acz'; //数据库用户名【需配置】
$dbpw = 'FKXwBDu'; //数据库密码【需配置】
$tbname = 'zi'; //数据表名【需配置】function getlink($query){
global $dbhost,$dbuser,$dbpw,$dbname;
$link = mysql_connect($dbhost, $dbuser, $dbpw)
or die('无法连接: ' . mysql_error()); mysql_query("set character set 'utf8'");
mysql_select_db($dbname) or die('不能连接数据库!');
mysql_query("SET NAMES UTF8"); // 执行 SQL 查询
$result = mysql_query($query) or die('查询失败: ' . mysql_error());
return $result;
}$bpa = "丨亅丿乛一乙乚丶八勹匕冫卜厂刀刂儿二匚阝丷几卩冂力冖凵人亻入十厶亠匸讠廴又艹屮彳巛川辶寸大飞干工弓廾广己彐彑巾口马门宀女犭山彡尸饣士扌氵纟巳土囗兀夕小忄幺弋尢夂子贝比灬长车歹斗厄方风父戈卝户火旡见斤耂毛木肀牛牜爿片攴攵气欠犬日氏礻手殳水瓦尣王韦文毋心牙爻曰月爫支止爪白癶歺甘瓜禾钅立龙矛皿母目疒鸟皮生石矢示罒田玄穴疋业衤用玉耒艸臣虫而耳缶艮虍臼米齐肉色舌覀页先行血羊聿至舟衣竹自羽糸糹貝采镸車辰赤辵豆谷見角克里卤麦身豕辛言邑酉豸走足青靑雨齿長非阜金釒隶門靣飠鱼隹風革骨鬼韭面首韋香頁音髟鬯鬥高鬲馬黄鹵鹿麻麥鳥魚鼎黑黽黍黹鼓鼠鼻齊齒龍龠"; //部首数组if($_POST['q']){ //搜索
$q = htmlspecialchars(trim($_POST['q']));
}elseif($_GET['id']){
$id = $_GET['id'];
//$id = intval(base64_decode($_GET['id']));
}elseif($_GET['list']){
$lst = intval($_GET['list']);
}function getR($q){ //搜索
global $bpa,$tbname;
if(preg_match("/^[A-Za-z]+$/",$q)){ //如果搜的拼音
$sql = "select id,zi from ".$tbname." where py = '".strtolower($q)."' limit 150";
}else{
$sql = "select id,zi from ".$tbname." where zi like '%".$q."%' limit 150";
}
$result = getlink($sql); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$res[] = $line;
}
if(count($res)==1) header("location: ?id=".$res[0]['id']);
return $res;
}function getArr($num,$t=0){ //获取缓存的数据
if($t==0){
$furl = "cache\\".floor(($num-1)/1000)."\\";
}else{
$furl = 'cache\\';
}
$filename = $furl.$num.".txt"; //缓存文件名 if(file_exists($filename)){
return unserialize(@file_get_contents($filename));
}else{
return false;
}
}function cacheArr($num,$arr,$t=0){ //将数据存下来
if($t==0){
$furl = "cache\\".floor(($num-1)/1000)."\\";
}else{
$furl = 'cache\\';
}
$filename = $furl.$num.".txt"; //缓存文件名 if(!file_exists($furl)){ //创建文件夹
if(!file_exists("cache\\") && $t==0){
mkdir("cache\\", 0777);
}
mkdir($furl, 0777);
} $t=serialize($arr);
$fp = @fopen($filename,"w");
@fwrite($fp,$t);
@fclose($fp);
}function listzidian($id){ //列表
global $bpa,$tbname,$is_cache;
if($is_cache==1){
$c = getArr($id,1);
if($c!=false) return $c;
} $pos = substr($bpa,$id*3-3,3); if($pos==""){
$sql = "select id,zi,bihua from ".$tbname." where bushou='难检字' or bushou='' order by bushou";
$res['type'] = "难检字";
}else{
$sql = "select id,zi,bihua from ".$tbname." where bushou='".$pos."' order by bushou";
$res['type'] = $pos;
}
$result = getlink($sql); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$res[] = $line;
}
if($is_cache==1){
cacheArr($id,$res,1);
}
return $res;
}function zidian($id){ //某个ID
global $is_cache,$tbname;
if($is_cache==1){
$c = getArr($id);
if($c!=false) return $c;
} $sql = "select * from ".$tbname." where id=".$id." limit 1";
$result = getlink($sql); $line = mysql_fetch_array($result, MYSQL_ASSOC);
if(!isset($line['zi'])) return false; $nsql = "select id,zi from ".$tbname." where id=".($id-1)." or id=".($id+1);
$nresult = getlink($nsql);
if($id==1){
$line[1] = null;
$line[2] = mysql_fetch_array($nresult, MYSQL_ASSOC);
}elseif($id==31715){
$line[1] = mysql_fetch_array($nresult, MYSQL_ASSOC);
$line[2] = null;
}else{
$line[1] = mysql_fetch_array($nresult, MYSQL_ASSOC);
$line[2] = mysql_fetch_array($nresult, MYSQL_ASSOC);
}

if($is_cache==1){
cacheArr($id,$line);
}
return $line;
}if($q){ //搜索
$zidianArr = getR($q);
if(count($zidianArr)==1) header("location: ?id=".$zidianArr[0]['id']);
$cha_title = $q." 的汉字搜索结果 - ".$title;
$zidianStatus = 1;
}elseif(isset($lst)){ //列表
if($lst<1) header("location: ./");
$zidianArr = listzidian($lst);
$cha_title = "偏旁部首为“".$zidianArr['type']."”的汉字 - ".$title;
$zidianStatus = 2;
}elseif(isset($id)){ //某ID
$zidianArr = zidian($id);
if(!isset($zidianArr['zi'])) header("location: ./");
$cha_title = $zidianArr['zi']." - ".$title;
$zidianStatus = 3;
}else{
$zidianStatus = 0;
$cha_title = $title;
}
?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$cha_title?></title></head><body>
<div align="center">
<table cellspacing="0" cellpadding="0" width="778" border="0"><tr><td align="left" style="padding:10px 0"><a href="http://zidian.911cha.com/" class="ttitle">新华字典</a></td></tr></table>
<table width="778" cellpadding="2" cellspacing="0" style="border:1px solid #B2D0EA;" id="top"><tr><td style="background:#EDF7FF;padding:0 5px;color:#014198;" height="26" valign="middle" colspan="5"><a href="http://www.911cha.com/">实用查询</a> &gt; <a href="./">新华字典</a></td></tr><tr><td align="center" valign="middle" height="60"><form action="index.php" method="post" name="f1"><input name="q" id="q" type="text" size="18" delay="0" value="" style="width:300px;height:22px;font-size:16px;font-family: Geneva, Arial, Helvetica, sans-serif;" onMouseOver="this.focus();" /> <input type="submit" value=" 查询 " /><br />查找汉字<span style="color:blue">卐</span>,直接输入<span style="color:blue">卐</span>,或其拼音<span style="color:blue">wan</span>即可</form></td></tr></table><br />
<? if($zidianStatus==0){ ?>
<? }elseif($zidianStatus==1){ //搜索 ?>
<table width="778" cellpadding="2" cellspacing="0" style="border:1px solid #B2D0EA;"><tr><td style="background:#EDF7FF;padding:0 5px;color:#014198;" height="26" valign="middle" colspan="5"><a href="./">新华字典</a> &gt; “<?=$q?>”的汉字搜索结果</td></tr><tr><td style="padding:8px;font-size:14px;">
<? if(count($zidianArr)==0){
if(preg_match("/^[\x{4e00}-\x{9fa5}]+$/u",$q)){ //全为中文
echo '<p class="f14">你输入了一个以上汉字,请输入一个汉字后查询!</p>';
echo '<p class="f14">或者:</p>';
echo '<p class="f14">  在 <a href="http://cidian.911cha.com/" class="f14" target="_blank">汉语词典</a> 里查找“<a href="http://cidian.911cha.com/q_'.urlencode($q).'" class="f14" target="_blank">'.$q.'</a>”的解释</p>';
echo '<p class="f14">  在 <a href="http://chengyu.911cha.com/" class="f14" target="_blank">成语词典</a> 里查找“<a href="http://chengyu.911cha.com/q_'.urlencode($q).'" class="f14" target="_blank">'.$q.'</a>”的解释</p>';
echo '<p class="f14">  在 <a href="http://baike.911cha.com/" class="f14" target="_blank">百科全书</a> 里查找“<a href="http://chengyu.911cha.com/q_'.urlencode($q).'" class="f14" target="_blank">'.$q.'</a>”的解释</p>';
}else{
echo '<p class="pink f14">你查询的不全为汉字,请剔除掉非汉字字符后再进行查询!<a href="./" class="f14">回'.$title.'首页</a></p>';
}
}else{
if(count($zidianArr)>=150) echo '<p class="f14 pink">返回结果数过多,仅列出前150个,请输入更准确的关键字进行搜索!</p><hr size="1" noshade="noshade" />';
echo '<p style="line-height:200%">';
for($i=0;$i<count($zidianArr);$i++){
echo '<a href="'.$zidianArr[$i]['id'].'.html" target="_blank">'.$zidianArr[$i]['zi'].'</a> ';
}
echo '</p>';
}
?>
</td></tr></table>
<? }elseif($zidianStatus==2){ //列表 ?>
<table width="778" cellpadding="2" cellspacing="0" style="border:1px solid #B2D0EA;"><tr><td style="background:#EDF7FF;padding:0 5px;color:#014198;" height="26" valign="middle" colspan="5"><a href="./">新华字典</a> &gt; 偏旁部首为“<?=$zidianArr['type']?>”的汉字</td></tr><tr><td style="padding:8px;font-size:14px;"><h1>偏旁部首为“<?=$zidianArr['type']?>”的汉字</h1><?
$bb = 0;
for($i=0;$i<count($zidianArr)-1;$i++){
if($zidianArr[$i]['bihua']>$bb){
if($i>0) echo '</p>';
echo '<p class="f14 b">笔画数'.$zidianArr[$i]['bihua'].':';
$bb = $zidianArr[$i]['bihua'];
}
echo '<a href="'.$zidianArr[$i]['id'].'.html" target="_blank" class="f14">'.$zidianArr[$i]['zi'].'</a> ';
}
?>
</td></tr></table>
<? }elseif($zidianStatus==3){ //某个ID ?>
<table width="778" cellpadding="2" cellspacing="0" style="border:1px solid #B2D0EA;"><tr><td style="background:#EDF7FF;padding:0 5px;color:#014198;" height="26" valign="middle" colspan="5"><a href="./">新华字典</a> &gt; <?
$pos = strpos($bpa,$zidianArr['bushou']);
if ($pos === false){
echo '<a href="?list=268">部首: 难检字</a>  &gt; ';
}else{
$pos=$pos/3+1;
echo '<a href="?list='.$pos.'">部首: '.$zidianArr['bushou'].'</a>  &gt; ';
}
?><?=$zidianArr['zi']?></td></tr><tr><td style="padding:8px;font-size:14px;word-break:break-all;"><h1 class="zi"><?=$zidianArr['zi']?></h1><?
if($zidianArr['pinyin']){ echo '<p><strong><a href="http://pinyin.911cha.com/" target="_blank">拼音</a></strong> '.$zidianArr['pinyin'].'</p>'; }
if($pos === false){
echo '<p><strong>部首</strong> <a href="?list=268" class="f14">难检字</a></p>';
}else{
echo '<p><strong>部首</strong> <a href="?list='.$pos.'" class="f14">'.$zidianArr['bushou'].'</a></p>';
}
if($zidianArr['wubi']){ echo '<p><strong><a href="http://wubi.911cha.com/" target="_blank">五笔</a></strong> '.$zidianArr['wubi'].'</p>'; }
if($zidianArr['bihua']){ echo '<p><strong><a href="http://bihua.911cha.com/" target="_blank">笔画</a></strong> '.$zidianArr['bihua'].'</p>'; }
if($zidianArr['lizi']){ echo '<p><strong>例子</strong> '.$zidianArr['lizi'].'</p>'; }
if($zidianArr['jijie']){ echo '<hr size="1" noshade="noshade" /><p><strong>基本解释</strong><br />'.$zidianArr['jijie'].'</p>'; }
if($zidianArr['xiangjie']){ echo '<hr size="1" noshade="noshade" /><p><strong>详细解释</strong><br />'.$zidianArr['xiangjie'].'</p>'; }
?>
</td></tr></table>
<? } ?></div>
</body>
</html>

解决方案 »

  1.   

    你找到那几个 header('Locaion 就找到位置了
    base64_decode 不能防止别人采集
    id=1

    id=OQ==
    不是一样的吗?
      

  2.   

    呵呵。这种方法只能对付菜鸟级别的人的。 
    如果是id=1 这种。一看就知道了,后面都是数字。只需要递增就行了。如果是id=OQ==   可以骗一下菜鸟级别的。 技术有限阿。
      

  3.   

    难道楼主需要这种效果:http://www.discoversources.com/Web-MDAxMDAzLTMtMjAxMi1JbmRleA==.dhtml
      

  4.   

    是的,就像这个
    http://www.vipcha.net/gougou/MjQy.html
      

  5.   

    header("location: ?id=".base64_decode($res[0]['id']));
    header("location: ?id=".base64_decode($zidianArr[0]['id']));
    我改了这两个。查询完,点链接。跳到首页去了。怎么办?
      

  6.   

    比如我输入一个汉字。然后查询。 然后会把信息显示出来。 这个信息包括超链接。/
    点这个超链接时。会跳到相应的?id=数字。我改了以后。超链接这里显示?id=数字。 但是一点就跳到首页去了
      

  7.   

    那你就是给错了文件
    在你给出的代码中没有在 url 中给 id 赋值的代码