<?
error_reporting(0);
include('inc.php');
?>
<!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=utf-8" />
<title>搜索引擎蜘蛛访问日志查看器</title>
<link rel="stylesheet" type="text/css" href="css/admin.css">
</head>

<body>

<div class="right">
  <? include "welcome.php"; ?>
  <div class="right_main">
<form name=form method=post id=form> 


 <table width="98%" border="0" cellpadding="4" cellspacing="1" class="tableoutline">
 <tr nowrap  class="tb_head">
          <td colspan="6" id="a"><h2>蜘蛛访问记录：服务器时间：<font style="COLOR: #ff0066"><?=gmdate("Y年n月j日 H:i:s",time()+8*3600)?></font></h2><h2 align="right"><a href=?del=del>清空记录</a></h2></td>
        </tr>
<?php

if($_GET[del]){
file_put_contents('../inc/bot.txt', "");
echo"<script>alert('\u5220\u9664\u6210\u529f');location.href='?';</script>";
}
?>
  <tr nowrap class="firstalt">
   <td width="50" height="30"><div align="center">ID</div></td>
   <td width="70"><div align="center">蜘蛛</div></td>
   <td width="120"><div align="center">蜘蛛IP</div></td>
   <td>来访页面</td>
   <td width="200">来访时间</td>
 </tr>
 <?php
 $page = isset ( $_GET ['page'] ) ? intval ( $_GET ['page'] ) : 1; //起始页
$list = get_content('../inc/bot.txt', $page, 30);

$l=count(file("../inc/bot.txt"));
if($l!=0 && file_exists("../inc/bot.txt")){
foreach ($list as $val) {
 $detail=explode("	",$val);
			   echo '<tr class="firstalt"><td>'.$i.'</td><td >'.$detail[2].'</td><td >'.$detail[1].'</td><td><a target="_blank" href="'.$detail[3].'">'.$detail[3].'</a></td><td>'.$detail[0].'</td></tr>'."\r\n";
}
 }
	   else{
	       echo '<tr align=center class="firstalt"><td colspan=5>暂时还没有蜘蛛访问</td></tr>';
		   }
/**
 * 反转输出自定义读取文本
 * @param   string $file  需要读取的文件
 * @param   int    $page  开始行数
 * @param   int    $pnum  一次截取行数(如：5行)
 * @return  array
 */
function get_content($file, $page, $pnum){ 
 $_arr = array();
 $str = file_get_contents($file);
 $arr = explode("\n", $str);
 
 if(is_array($arr)){
  $begin = count($arr) - $page < count($arr) ? count($arr) - $page : count($arr) - 1;
  $end = $begin - $pnum + 1;
  
  for($i = $begin; $i >= $end; $i--){ 
   $_arr[] = $arr[$i];
  }
 }
 return $_arr;
}
/*$list=file("../inc/bot.txt");
$l=count($list);


if($page<1||$page>$l) $page=1;
$pnum=100;
$begin=($page-1)*$pnum;
$end=($begin+$pnum)>$l?$l:$begin+$pnum;
for($i=1;$i<=ceil($l/$pnum);$i++){
    echo "<a href=?page=${i}>${i}</a>";
}
if($l!=0 && file_exists("../inc/bot.txt")){
		for($i=$begin;$i<$end;$i++){
	           $detail=explode("	",$list[$i]);
			   echo '<tr class="firstalt"><td>'.$i.'</td><td >'.$detail[2].'</td><td >'.$detail[1].'</td><td><a target="_blank" href="'.$detail[3].'">'.$detail[3].'</a></td><td>'.$detail[0].'</td></tr>'."\r\n";
			   if(empty($detail[0]) || $detail[0]==''){
			   break;
			   }
			  
	       }
	   }
	   else{
	       echo '<tr align=center class="firstalt"><td colspan=5>暂时还没有蜘蛛访问</td></tr>';
}*/
?></table>
</div>
</div>
<? include "footer.php"; ?>
</body>
</html>

