$f_p = open("./ip.txt",'a+');
fwrite("|".date("Y-m-d")."|".$_SERVER['REMOTE_IP']."|", $f_p);
fclose($f_p);that's all!

解决方案 »

  1.   

    还要加一条。。先写入cookie或session判断是否为同一用户。不然有你空间好受的。。  ^______________^
      

  2.   

    我套用后:
    Fatal error: Call to undefined function: open()
    怎么办??
    呵呵!
    我是菜鸟!!
    望大家指点!!
    ^_^
      

  3.   

    fwrite("|".date("Y-m-d")."|".$_SERVER['REMOTE_IP']."|", $f_p);
    这句也有问题!!
    怎么改呢 ?
      

  4.   

    支持的啊!
    我是说 fwrite("|".date("Y-m-d")."|".$_SERVER['REMOTE_IP']."|", $f_p);
    这句的语法/拼写是不对的,比如:
    $_SERVER['REMOTE_IP']."|"  ??!!!
    但我不懂用fwrite
      

  5.   

    我用decolee() 的办法:一运行马上就:
    Warning: fwrite(): supplied argument is not a valid stream resource in...
    应该是fwrite("|".date("Y-m-d")."|".$_SERVER['REMOTE_IP']."|", $f_p);
    这句的问题,但不懂怎么改,!
      

  6.   

    我把$_SERVER['REMOTE_IP']
    改为$_SERVER['REMOTE_ADDR']
    也不行!
      

  7.   

    fwrite($f_p,"|".date("Y-m-d")."|".$_SERVER['REMOTE_ADDR']."|");
    参数顺序错了
      

  8.   

    fwrite($f_p,"|".date("Y-m-d")."|".$_SERVER['REMOTE_ADDR']."|\r\n");
    因该还要换行吧
    window:\r\n
    unix:\n
    mac:\r
      

  9.   

    OK,感谢个各位了!
    但这样一来,就是同一Ip
    添加得都相当频繁,
    怎样限制同一ip在一个时间段范围内只
    添加一条ip记录呢?
    有什么比较高效率的办法呢?
    谢谢!
      

  10.   

    一个简单的统计程序<?php
    /*****************功能:在线统计****************/
    /************Programmed By SurfChen***********/
    /**********http://www.yubeinet.com/bbs********/
    /**********http://surfchen.wegame.com*********/
    /*********************************************
    使用说明:(假设本文件名为stat.php,并与所要统计页面处于同一目录)
    在所要统计的PHP页面的代码加上一句include("stat.php");,然后就可以在本页面获得5个变量:
    $yb_ip; 访客IP $yb_addr; 访客所处地理位置(暂时无此功能)  $online_now; 在线人数  $online_his;最高在线人数 $guest_num;访问总数
    如果是静态HTML页面,可以加入<iframe width=0 height=0 src="stat.php"></iframe>,可以更新数据,但是无法取得变量
    由于时间比较紧,暂时没有其他额外的功能,可能也没必要吧。如果谁想加别的功能。请联系[email protected]
    ***********************************************/
    /**********************************************/$ginfo_file="data/guest_info.php";//访客信息文件,请自行建立并设置所属文件夹属性为777
    $gonline_file="data/guest_online.php";//最高在线文件,请自行建立,并在文件里手工输入任意一个数字,并设置所属文件夹属性为777
    $cut_time="600";//在线更新时间,单位为秒/*获取IP地址和物理地址开始(本功能暂时无法使用)
    ob_start();
    include("http://www.proxycn.com/ip/");
    $content=ob_get_contents();
    preg_match("/(\d*)\.(\d*)\.(\d*)\.(\d*)/ism",$content, $matches);
    $yb_ip = $matches[0];
    preg_match("/#CC0000><b>(.*)<\/b><\/font>/sU",$content, $matches);
    $yb_addr=$matches[1];
    ob_end_clean();
    if ($yb_ip==null)
    {
    $yb_ip=$_SERVER['REMOTE_ADDR'];
    }
    if ($yb_addr==null)
    {
    $yb_addr="未知地址";
    }
    获取IP地址和物理地址结束*/
    $yb_ip=$_SERVER['REMOTE_ADDR'];
    $yb_addr="目前无数据";
    /*判断用户是否在线开始*/
    $now=time();
    $file_info=file($ginfo_file);
    $guest_num=count($file_info);
    foreach ($file_info as $key => $value)
    {
    $st="off";
    $ginfo=explode("|",$value);
    $his_time=rtrim($ginfo[2]);
    if ($ginfo[0]==$yb_ip && ($now-$his_time)<=$cut_time)
    {
    $st="on";
    $line=$key;
    break;
    }
    }
    /*判断用户是否在线结束*/if ($st=="on")
    {
    /*更新在线用户的活动时间*/
    $info="";
    $file_info=file($ginfo_file);
    foreach ($file_info as $key => $value)
    {
    if ($key==$line)
    {
    $p=explode("|",$value);
    $v=$p[0]."|".$p[1]."|".$now."\n";
    $info.=$v;
    }
    else
    {
    $info.=$value;
    }
    }
    $handle=fopen($ginfo_file,"w");
    flock($handle,LOCK_EX);
    fwrite($handle,$info);
    fclose($handle);}
    else 
    {
    $guest_num++;
    /*记录在线用户资料*/
    $info=$yb_ip."|".$yb_addr."|".$now."\n";
    $handle=fopen($ginfo_file,"a");
    flock($handle,LOCK_EX);
    fwrite($handle,$info);
    fclose($handle);
    }
    /*统计最高在线人数*/
    $file_info=file($gonline_file);
    $online_his=$file_info[0];
    $file_info=file($ginfo_file);
    foreach ($file_info as $key => $value)
    {
    static $online_now=0;
    $ginfo=explode("|",$value);
    $ginfo_time=rtrim($ginfo[2]);
    if (($now-$ginfo_time)<=$cut_time)
    {
    $online_now++;
    }
    }
    if ($online_now>$online_his)//更新最高在线人数
    {
    $handle=fopen($gonline_file,"w");
    flock($handle,LOCK_EX);
    fwrite($handle,$online_now);
    fclose($handle);
    $online_his=$online_now;
    }
    /*echo $yb_ip;
    echo "<br>";
    echo $yb_addr;
    echo "<br>";
    echo $online_now;
    echo "<br>";
    echo $online_his;*/
    ?>
      

  11.   

    apache已经有这个功能了.windows:
    c:\apache\logs\access.txt
      

  12.   

    进行文件操作很简单:
    首先你要有权限,
    然后你就是要打开该文件.可以用fopen(),file()等等函数.
    然后就是写了.接着关闭文件...