count.php
<?php$result=file("./count.txt");
echo $result[0];$result[0]=$result[0]+1;$fp=fopen("count.txt","r+");
fwrite($fp,$result[0]);
?>index.php中的调用语句
<marquee>您是第<?php include "count.php"?>位光顾者</marquee> count.txt中
方一个数字就可以了
如39
就是这样,以前写的,
<?php$result=file("./count.txt");
echo $result[0];$result[0]=$result[0]+1;$fp=fopen("count.txt","r+");
fwrite($fp,$result[0]);
?>index.php中的调用语句
<marquee>您是第<?php include "count.php"?>位光顾者</marquee> count.txt中
方一个数字就可以了
如39
就是这样,以前写的,
解决方案 »
- iis 创建ftp时 报530错误 iis板块人气不旺
- 在线等,谢谢大家了!!!!Fatal error: Call to undefined function mssql_connect() in
- php 站内搜索怎么实现,有哪些好的方法?
- 求Paypal的支付接口代码
- 送分问题
- PHP 无法获取session的值. 请高手给答案啊!
- Parse error: syntax error, unexpected T_VARIABLE 各位帮我看看有什么问题
- 再提问,还是正则表达式
- 对一个2维数组安照某个字段排序,发现对字符类型的排序不够理想
- 在phpmyadmin现在突然不能增加记录了,请帮忙看看
- 请教chinaren校友录的数据库是如何建立的?
- 急!!变量的传递
出错原因:第21行应为fclose($p),而不是fcolse($p),粗心!^_^
另一个原因可能是:在本机运行一般都会出错,因为并没有对count.txt有可写的权限!//我不知道那个counter.txt的文件应该新建在哪里,里面用写些什么么?
放在和这个计数的PHP文件同一目录下!什么都不用写,会自动写进去!//而且它现在起不到计数的作用,刷新网页数字还是不变,我觉得问题还是出在那个.txt文件上了,请求大家的帮助!
刷新网页数字还是不变,因为并没有对count.txt有可写的权限!所以数没有加上去,上传到你支持PHP的空间试试,应该就没问题了,我以前也遇到过这样的情况!
read write execute
owner * * *
group * * *
other * * *
修改权限为777 。
在本目录用 0.gif ------ 9.gif........显示<?
//counter.php3/////////////////////////////////////////////////////
/////////----- [email protected] //////////
///////////////////////////////////////////////////$yourip=$REMOTE_ADDR." ".$HTTP_USER_AGENT;
$yourip_min=$REMOTE_ADDR;function IPisOutside($ip)
{
if (substr($ip,0,3)=="192" ||
substr($ip,0,3)=="172" ||
substr($ip,0,3)=="127")
{
return false;
}
return true;
}function counter()
{
global $yourip;
global $yourip_min;
$basedir="./";
$counterFile=$basedir."_counter_.txt";
if (!file_exists($counterFile))
{
//die("计数器记录文件丢失!");
$fp=fopen($counterFile,"w");
fputs($fp,"");
fclose($fp);
}
$fd=@fopen($counterFile,"r");
$str=@fread($fd,255);
$str_array=@explode("||",$str);
while(list($key,$value)=each($str_array))
{
$count[$key]=$value;
}
@fclose($fd);
$num=$count[0]*1;
$ip=$count[1];
/////////
$total_count_in_out_tmp=@explode(",",$count[2]);
$total_count_in=$total_count_in_out_tmp[0]*1;
$total_count_out=$total_count_in_out_tmp[1]*1;
/////////
$total_days=$count[7]*1;
$average_day_in=$count[4]*1;
$p1_array=@explode(",",$count[3]);
$in_date_count=$p1_array[0]*1;
$in_date=$p1_array[1];
$average_day_out=$count[6];
$p2_array=@explode(",",$count[5]);
$out_date_count=$p2_array[0]*1;
$out_date=$p2_array[1];
if (date("Y-m-d")<>"$in_date")
{
$total_days++;
$average_day_in= round( ($in_date_count + $average_day_in*($total_days-1))/$total_days);
$in_date=date("Y-m-d");
$average_day_out= round( ($out_date_count + $average_day_out*($total_days-1))/$total_days);
$out_date=date("Y-m-d");
$in_date_count=0;
$out_date_count=0;
}
if($ip!=$yourip) //若想不以IP统计,请注释此行
{
$num++;
if (IPisOutside($yourip)==false)
{
$total_count_in++;
$in_date_count++;
}
else
{
$total_count_out++;
$out_date_count++;
}
}
///////////
$fd=@fopen($counterFile,"w");
fputs($fd,"$num||$yourip||$total_count_in,$total_count_out||$in_date_count,$in_date||$average_day_in||$out_date_count,$out_date||$average_day_out||$total_days");
fclose($fd);
$average_day_total=$average_day_in+$average_day_out;
$counter_info="<IP访客计数器>\n总访问量 $num"."\n内部 $total_count_in"."\n外部 $total_count_out"."\n----------\n平均日访问量 $average_day_total"."\n内部 $average_day_in"."\n外部 $average_day_out"."\n----------\n你的IP是 $yourip_min";
$count_len=strlen($num);
for($i=0;$i<$count_len;$i++)
{
$ok[$i]=substr($num,$i,1).".gif";
echo "<img src='$basedir$ok[$i]' width=\"7\" height=\"10\" title=\"$counter_info\">";
/////////////////////
}
} counter();
?>
。这个程序我按书上打过(很仔细的)没问题。只是后面那个例子,图形计数器,没成功,因为我没装gd-library.