From 862b38e720d5533c855019d0b29ee3446e5f19fd Mon Sep 17 00:00:00 2001 From: grt1st Date: Tue, 7 Mar 2017 16:46:26 +0800 Subject: [PATCH] Update search.php --- search.php | 327 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 196 insertions(+), 131 deletions(-) diff --git a/search.php b/search.php index 7ffe624..9379878 100644 --- a/search.php +++ b/search.php @@ -1,180 +1,245 @@ - - + 乌云搜索|搜索结果 - - - - + + + + -
-
- search from wooyun.org - -
-
+ + + +
+ 关键词【".$keywords."】的搜索结果:"; -#$sql="select * from bugs where title like "; -#$res=$pdo->query($sql); -#SELECT count(*) FROM `bugs` WHERE `title` LIKE \'%腾讯%\' -#SELECT* FROM `bugs` WHERE `title` LIKE '%腾讯%' LIMIT 0,4 -#title,datas,author,doc,type +echo "

关键词【{$keywords}】的搜索结果:

"; -//mysql建立连接 -$db=new mysqli('localhost','root','','wooyun'); -//sql对象错误检查 -if(mysqli_connect_errno()){ - echo '
Error:Please try again later.'; - exit(); +//pdo连接mysql +try +{ + $conn = new PDO("mysql:host={$config['host']};dbname={$config['database']};port={$config['port']};charset=utf8", $config['user'], $config['passwd']); + //echo "mysql:host={$config['host']};dbname={$config['database']}"; } -// 建立查询 -$db->set_charset("utf8"); -#drops -//分页处理 -if($kind==='author'){ - $query0="SELECT count(*) FROM `bugs` WHERE author LIKE '%".$keywords."%'"; - $query1="SELECT count(*) FROM `drops` WHERE author LIKE '%".$keywords."%'"; -} -else{ - $query0="SELECT count(*) FROM `".$kind."` WHERE `title` LIKE '%".$keywords."%'"; +catch (PDOException $pe) +{ + die("Could not connect to the database $dbname :" . $pe->getMessage()); } -$num=$db->query($query0); -$row=$num->fetch_row(); -if($kind==="author"){ - $num1=$db->query($query1); - $rows=$num1->fetch_row(); - $row[0]+=$rows[0]; +//查询数目 +if ($kind === 'author') +{ + $query0 = "SELECT count(*) FROM `bugs` WHERE author LIKE '%{$keywords}%'"; + $query1 = "SELECT count(*) FROM `drops` WHERE author LIKE '%{$keywords}%'"; + $res0 = $conn->query($query0); + $res1 = $conn->query($query1); + $row = $res0->fetch(PDO::FETCH_NUM)[0] + $res1->fetch(PDO::FETCH_NUM)[0]; } +else +{ + $query0="SELECT count(*) FROM `{$kind}` WHERE `title` LIKE '%{$keywords}%'"; + $res0 = $conn->query($query0); + $row = $res0->fetch(PDO::FETCH_NUM)[0]; +} + //得到总页数 $p -if($row[0]%15!=0){ - $p=intval($row[0]/15)+1; +if ($row % 15 != 0) +{ + $p = intval($row / 15) + 1; } -else{ - $p=$row[0]/15; +else +{ + $p = $row / 15; } -if($row[0]==0) $p=1; -if($page>$p || $page<1){ - $page=1; +if ($row == 0) $p = 1; +if ($page > $p || $page <1 ) $page = 1; + +echo "

共 {$row} 条记录

"; + +$start = ($page - 1) * 15; + +if ($kind === 'author') +{ + $query = "(SELECT doc,dates,title,type,author FROM `bugs` WHERE `author` LIKE '%{$keywords}%') UNION ALL (SELECT doc,dates,title,type,author FROM `drops` WHERE `author` LIKE '%{$keywords}%')ORDER BY dates DESC LIMIT {$start},15"; } -echo "

共 ".$row[0]." 条记录

"; -$start=($page-1)*15; -if($kind==='author'){ - $query="(SELECT doc,dates,title,type,author FROM `bugs` WHERE `author` LIKE '%".$keywords."%') UNION ALL (SELECT doc,dates,title,type,author FROM `drops` WHERE `author` LIKE '%".$keywords."%')ORDER BY dates DESC LIMIT ".$start.",15"; +else +{ + $query = "SELECT * FROM `{$kind}` WHERE `title` LIKE '%{$keywords}%' ORDER BY dates DESC LIMIT {$start},15"; } -else{ - $query="SELECT * FROM `".$kind."` WHERE `title` LIKE '%".$keywords."%' ORDER BY dates DESC LIMIT ".$start.",15"; + +$res = $conn->query($query); +$resulte = $res->fetchAll(PDO::FETCH_ASSOC); +//var_dump($resulte); + +//输出结果 +echo '
'; +echo ''; + +foreach ($resulte as $rrr){ + if ($kind != "author") + { + echo ""; + } + else + { + if (array_key_exists($rrr['type'], $drops)) + { + echo ""; + } + else + { + echo ""; + } + } + + $time0 = str_split($rrr['dates'], 10); + echo ""; + echo ""; + if (array_key_exists($rrr['type'], $drops)) + { + echo ""; + } + else + { + echo ""; + } + echo ""; + echo ""; } -//执行查询 -$result=$db->query($query); -//逐行分解result -#echo "
"; -echo "
提交时间标题漏洞类型提交者
{$time0[0]}{$rrr['title']}{$drops[$rrr['type']]}{$rrr['type']}{$rrr['author']}
"; -echo ""; - for($i=0;$i<$result->num_rows;$i++){ - $row_result=$result->fetch_object(); - if($kind!="author"){ - echo "doc."');\" style=\"cursor:pointer;\">"; - } - else{ - if($row_result->type=="binary" || $row_result->type=="mobile" || $row_result->type=="mobiledev" || $row_result->type=="database" || $row_result->type=="news" || $row_result->type=="papers" || $row_result->type=="pentesting" || $row_result->type=="tips" || $row_result->type=="tools" || $row_result->type=="web" || $row_result->type=="wireless" || $row_result->type=="safe"){ - echo "doc."');\" style=\"cursor:pointer;\">"; - } - else{ - echo "doc."');\" style=\"cursor:pointer;\">"; - } - } - $time0=str_split($row_result->dates,10); - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - } echo "
提交时间标题漏洞类型提交者
'.$time0[0].''.$row_result->title.''.$row_result->type.''.$row_result->author.'
"; -// 显示result -// 释放连接,关闭sql. -$result->free(); -$db->close(); + +$conn = null; + //分页 -echo "
"; -echo "
    "; +echo '
      '; //首 -if($page==1){ - echo "
    • «
    • "; +if ($page==1) +{ + echo '
    • «
    • '; } -else{ - echo "
    • «
    • "; +else +{ + echo "
    • «
    • "; } //中间处理 -if($p>17){ - if($page<9){ +if ($p > 17) +{ + if ($page < 9) + { $i=1; } - elseif($page>=9 && $page+8<$p){ - $i=$page-8; + elseif ($page >= 9 && $page + 8 < $p) + { + $i = $page-8; } - elseif($page+8>=$p){ - $i=$p-8; + elseif ($page + 8 >= $p) + { + $i = $p-8; } - $j=$i+17; + $j = $i + 17; } -else{ - $i=1; - $j=$p; +else +{ + $i = 1; + $j = $p; } //echo $p; -for(;$i<=$j;$i++){ - if($page==$i){ - echo "
    • ".$i."
    • "; +for (;$i <= $j;$i++) +{ + if ($page == $i) + { + echo "
    • {$i}
    • "; } - else{ - echo "
    • ".$i."
    • "; + else + { + echo "
    • {$i}
    • "; } } //尾 -if($page==$p || $p==0){ - echo "
    • »
    • "; - } - else{ - echo "
    • »
    • "; - } -echo "
"; +if ($page == $p || $p ==0) +{ + echo '
  • »
  • '; +} +else +{ + echo "
  • »
  • "; +} +echo ""; + + ?> -
    数据来源于wooyun.org
    -
    + + +
    + + + + +