<?php @error_reporting (E_ALL & ~E_NOTICE & ~E_WARNING); set_time_limit(0); $prescription = trim($_GET['q']); $id = intval(base64_decode($_GET['id'])); $r_num = 0; //结果个数 $lan = 2; //首页分列 $pf = ""; $pf_l = ""; $page=is_numeric($_REQUEST['page'])?$_REQUEST['page']:1; $dreamdb=file("date/jf.dat");//读取库 $count=count($dreamdb);//计算行数 $zs=intval($count/30); if($prescription!=""){ $searchCount = 0;//搜索结果个数 for($i=0; $i<$count; $i++) { $keyword=explode(" ",$prescription);//拆分关键字 $dreamcount=count($keyword);//关键字个数 for ($ai=0; $ai<$dreamcount; $ai++) { @eval("\$found = eregi(\"$keyword[$ai]\",\"$dreamdb[$i]\");"); if(($found)){ if($searchCount < 60) { $detail=explode("\t",$dreamdb[$i]);//按tab if(fmod($r_num,$lan)==0) $pf_l .= "<tr>"; $pf_l .= '<td width="'.(100/$lan).'%"><img src="/img/dot.gif" />'; $pf_l .= '<a href="'.base64_encode(($i+1)).'.html">'.($r_num+1).":".$detail[0].'</a></br></td>'; if(fmod($r_num,$lan)+1==$lan) $pf_l .= "</tr>"; } $r_num++; $searchCount++; } } } $info = '<div class="zt"><b><a href="./">酒方大全</a>:找到 <a href="./?q='.urlencode($prescription).'"><font color="#c60a00">'.$prescription.'</font></a> 的相关'.$r_num.'个</b>'; if($searchCount > 60) { $info .= ' <font color="#c60a00">[由于数据太多,本次查询只显示前60条,请核实您输入的信息准确性]</font>'; } $pf_l = $info.'</div><div class="wenzi"><table cellpadding="5" cellspacing="10" width="100%">'.$pf_l.'</table></p></div> <!--内容结束--> '; }else{ if($id > 0) { $detail_only=explode("\t",$dreamdb[$id-1]); $pf = '<div class="zt"><b><a href="./">酒方大全</a> /'.$detail_only[0].'</b><td align="right">'; if($id>1 && $id<=$count) $pf .= '<a href="'.base64_encode(($id-1)).'.html">上一个</a> '; $pf .= '<a href="./">查看全部</a>'; if($id>=1 && $id<$count) $pf .= ' <a href="'.base64_encode(($id+1)).'.html">下一个</a>'; $pf .= '</td></tr><tr></div><div class="wenzi"><table cellpadding="5" cellspacing="10" width="100%"><tr><td colspan="3"> <h2>'.$detail_only[0].'</h2><br />'.$detail_only[3].'</td></tr></table></div>'; } $pfl = rand(0,intval($count/30)); for($i=$page*30; $i<$page*30+30; $i++) { if($i>=$count-1) break; $detail=explode("\t",$dreamdb[$i]); if(fmod($r_num,$lan)==0) $pf_i .= "<tr>"; $pf_i .= '<td width="'.(100/$lan).'%"><img src="/img/dot.gif" />'; $pf_i .= '<a href="'.base64_encode(($i+1)).'.html">'.$detail[0].'</a></br></td>'; if(fmod($r_num,$lan)+1==$lan) $pf_i .= "</tr>"; $r_num++; } $pf_i = '<div class="zt"><b>推荐<a href="./">酒方大全</a>'.$count.'个</b></div><div class="wenzi"><table cellpadding="5" cellspacing="10" width="100%">'.$pf_i.'</table> </p></div><!--内容结束-->'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>酒方大全_药酒配方_在线酒方查询</title> </head> <body> <div align="center"> <br /> <form action="./" method="get" name="f1"> <input name="q" type="text" size="20" maxlength="20" /> <input type="submit" id="sub" value="查询" /></form> <?php if($prescription!=""){ echo $pf_l; }else{ if($id > 0 && $id < $count) { echo $pf; } echo $pf_i; } ?> </div> </body> </html>
主要说的是你: <font color="#c60a00">'.$prescription.'</font>这个地方 你这样显示,如果$prescription的内容是恶意的HTML、js代码,那它就会直接执行了。 显示之前用stripslashes处理下就好。
$prescription = trim($_GET['q']); <a href="./?q='.urlencode($prescription).'"> <input name="q" type="text" size="20" maxlength="20" /> 这是 url 参数 q 的几次出现的地方 是否会招来 XSS 攻击这很难说,但不验证传入参数的来源和合法性总是不妥的 你至少需要将表单的提交方式由 get 改成 post
20,359
社区成员
19,658
社区内容
加载中
试试用AI创作助手写篇文章吧