<html>
<head>
<meta http-equiv="refresh" content="10; url=many.php">
</head>
<body>
<center>
<?
$time=gettimeofday(void);
$tmp=file("time.txt");
if ($tmp[0]=="")
{  $fopen0=fopen("time.txt","w+");
  fputs($fopen0,$time[sec]);
  fclose($fopen0);  $fopen1=fopen("ip.txt","w+");
  fputs($fopen1,"");
  fclose($fopen1);
}
$tmp1=file("time.txt");
$equal=($time[sec]-$tmp1[0]);
if ($equal>60)
{  $fopen0=fopen("time.txt","w+");
  fputs($fopen0,"");
  fclose($fopen0); 
}$fopen=fopen("ip.txt","a+");
$ip=$REMOTE_ADDR;$flag=1;
$tmp2=file("ip.txt");
$con=count($tmp2);for ($i=0;$i<$con;$i++)
{
  if ($ip."\n"==$tmp2[$i])
  {
    $flag=0;
    break;
  }
}if ($flag==1)
{
  $ipstring=$ip."\n";
  fputs($fopen,$ipstring);
}
fclose($fopen);$tmp3=file("ip.txt");
$value=count($tmp3);
echo "目前線上人數:".$value;
?>
</center>
</body>
</html>

解决方案 »

  1.   

    第一种方法:利用AltaVista搜索引擎来实现   这种方法是检查与你的站点链接的数目。这里用AltaVista搜索引擎来实现。 
       在这里,我们用如下搜索引擎: 
    http://www.altavista.com/cgi-bin/query?kl=XX&pg=q&text=yes&q=link%3A&search=Search。 
       这是AltaVista的一个文本版本。这样可以节省我们大量的需要解析HTML的代码。接着,我们使用rawurlencode()来处理我们确切的URL保证Altavista能够正确地处理它。处理如下: 
    <? 
    $url = "http://www.oso.com.cn"; 
    $url_encoded = rawurlencode($url); 
    $url_to_check = "http://www.altavista.com/cgi-bin/query? 
    kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search"; 
    ?> 
      这样,我们可以通过file()函数回取URL了。 
    <? 
    $num_searched = file($url_to_check); 
    ?> 
      现在我们所取回的文件已经存放在数组$num_searched中。现在要在数组中查找我们想要的文本"About (.*) pages found. "。(.*)表示在任何东西。而且,如果没有人链接我们的URL,AltaVista将显示"AltaVista found no document matching your query."。因为我们想知道多少个人正在与我们的URL进行着链接,那段文本将被看作0个人链接。 
    <? 
    $url = "http://www.oso.com.cn"; 
    $url_encoded = rawurlencode($url); 
    $url_to_check = "http://www.altavista.com/cgi-bin/query?kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search"; 
    $num_searched = file($url_to_check); 
    for ($i = 0; $i < count($num_searched); $i++) { 
    if(eregi( "About (.*) pages found.", $num_searched[$i])){ 
    $total_links = eregi_replace( "<P>About (.*) pages found.", "1", $num_searched[$i]); 

    elseif(eregi( "AltaVista found no document matching your query.",$num_searched[$i])){ 
    $total_links = "0"; 

    } ?> 
      这样,我们可以通过打印语句得到我们的查找结果了: 
    print("<a href="$url_to_check">$total_links people are linking to $url</a>");
    第二种方法:利用MYSQL数据库 
    以下是我转贴的一篇文章,来自于PHP中文用户,起方式是利用临时数据表处理当前连接,具体内容如下: *************************************************************** 
    首先,用MySQL的工具建一个表: CREATE TABLE ccol( 
    id integer not null auto_increment, ip char(15) not null, dtstamp datetime not null, uri char(255), primary key (id) 
    ); 然后,写一段PHP代码: <? 
    /* 
    文件:ccol.php - ConCurrent OnLine statistics 
    目的:统计同时在线浏览的人数 
    作者:Hunte, [email protected] 
    修改:2000-4-25 
    */ $duration=1800; 
    require "db.php"; 
    //包含DBSQL,详情可以参考我的另一篇文章 
    $ccol=new dbSQL; 
    $ccol->connect(); 
    $ccol->query("DELETE FROM ccol WHERE (UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(dtstamp))>$duration"); 
    //删除超过半小时的记录 
    $ccol->query("SELECT * FROM ccol WHERE ip="$REMOTE_ADDR""); 
    //判断当前的IP是否在该表中存在 
    if ($ccol->nf())//有? 

    $ccol->next_record();//下移找到的记录数组的指针 
    $id=$ccol->f("id"); 
    $ccol->query("UPDATE ccol SET dtstamp=now(), uri="$REQUEST_URI" WHERE id=$id"); 
    //设置最后访问时间和访问页面 

    else//没有 

    $ccol->query("INSERT INTO ccol VALUES (0, "$REMOTE_ADDR", now(), "$REQUEST_URI")"); 
    } $ccol->query("SELECT COUNT(*) AS ccol FROM ccol WHERE (UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(dtstamp))<=$duration"); 
    //找出在半个小时内的记录,后面的WHERE子句可有可无--超出时间的已经被删除了 
    $ccol->next_record() 
    echo "在线人数:", $ccol->f("ccol"); 
    $ccol->free_result(); 
    ?> 怎么用呢?在站点的每个页面的上面调用这个程序,举例来说: 
    --index.php 
    ... 
    <!--显示在线人数-> 
    <?require ../stats/ccol.php?> 
    ... 当然,这段代码还有改进的余地。例如,在每次调用是都要删除半小时前的记录,这是没有必要而且会降低效率。可以一个什么办法过更长的时间再做,比如6小时。大家自个儿想想吧,我就不说了。 这种方法只要稍做修改,就可以派上别的用处,如SESSION的管理、网站的访问统计分析等。