<?php$file = "counter.txt";
//File name//That's itif( ! file_exists( "$file" ) ) {
touch( "$file" );
chmod("$file",0777);
$fp=fopen("$file","r+");
fseek($fp,0);
$compteur = 0;
fputs($fp,$compteur);
}if( is_readable( "$file") and is_writable( "$file") ) {$fp=fopen("$file","r+");
$compteur=fgets($fp,9999);
fseek($fp,0);
$compteur++;
fputs($fp,$compteur);
fclose($fp);
print $compteur;
} else {
chmod("$file",0777);
}?>
//File name//That's itif( ! file_exists( "$file" ) ) {
touch( "$file" );
chmod("$file",0777);
$fp=fopen("$file","r+");
fseek($fp,0);
$compteur = 0;
fputs($fp,$compteur);
}if( is_readable( "$file") and is_writable( "$file") ) {$fp=fopen("$file","r+");
$compteur=fgets($fp,9999);
fseek($fp,0);
$compteur++;
fputs($fp,$compteur);
fclose($fp);
print $compteur;
} else {
chmod("$file",0777);
}?>
解决方案 »
- 求一个php的小代码
- XML标签语法错误 : name="list" id="vo" 请教!!!!!
- 帮忙分析下这段代码的执行过程。。。
- 伪静态权限问题
- vista 怎么設置php 環境?
- 提示:Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- 有什么方法要以直接输出HTML代码,而不需要通过字符串转换?
- php有没有什么在各平台通用的锁或者其他的同步机制?
- php+sql server连接的问题
- 请问如何判断客户端的cookie是否是打开的。如何实现了?
- php的配置问题
- PHP如何向已经存在的excel输入数据?
贴过n次了。唉。$userip=$REMOTE_ADDR;//访问计数
$row3=@mysql_fetch_array(@mysql_query("select * from homepage where title='count'"));
if($row3[content]<>$userip) @mysql_query("update homepage set hit=hit+1,content='$userip' where title='count'");
这是数据库类型的。自建一个表先。
if(ip地址不同 or (当前访问时间 - 同一IP上次访问时间) > 300){
#其中300为5分钟,具体楼主可以根据需要修改
$counter += 1;
update 该IP最后访问时间
}//以上即为记数过程
echo $counter;//显示访问人数
session_start();
if(! isset($_SERVER['counter'])) {
$_SERVER['counter'] = 1; //这里放任意计数器代码,比如Amely(海贝) 的}
?>
可以使用的有cookie or session都可以.但使用cookie session有一个缺点,就是如果,别人把页面关了,重新打开,就又可以算了.
(当然,你可以设定cookie时间,如半个小时的样子)最好的方法当然是记录IP了,但楼主要求的是文本的.可能做不到.
你一刷新他就自动增加.可以考虑唠叨大哥的写法..
<?php
session_start();
if(! isset($_SERVER['counter'])) {
$_SERVER['counter'] = 1;
$file = "counter.txt ";
//File name
//That's it
if( ! file_exists( "$file " ) ) {
touch( "$file " );
chmod( "$file ",0777);
$fp=fopen( "$file ", "r+ ");
fseek($fp,0);
$compteur = 0;
fputs($fp,$compteur);
}
if( is_readable( "$file ") and is_writable( "$file ") ) {
$fp=fopen( "$file ", "r+ ");
$compteur=fgets($fp,9999);
fseek($fp,0);
$compteur++;
fputs($fp,$compteur);
fclose($fp);
print $compteur;
} else {
chmod( "$file ",0777);
}
}
? >
<?php
session_start();
if(! isset($_SERVER['counter'])) {
$_SERVER['counter'] = 1;
$file = "counter.txt ";
//File name
//That's it
if( ! file_exists( "$file " ) ) {
touch( "$file " );
chmod( "$file ",0777);
$fp=fopen( "$file ", "r+ ");
fseek($fp,0);
$compteur = 0;
fputs($fp,$compteur);
}
if( is_readable( "$file ") and is_writable( "$file ") ) {
$fp=fopen( "$file ", "r+ ");
$compteur=fgets($fp,9999);
fseek($fp,0);
$compteur++;
fputs($fp,$compteur);
fclose($fp);
print $compteur;
} else {
chmod( "$file ",0777);
}
}
? >
有人用网关上网的,一群人用同一个公网IP设置Session过期时间更准确一些
Cookie并不是关掉浏览器就失效,Cookie设置时间很方便
session_start();
if(! isset($_SERVER['counter'])) {
$_SERVER['counter'] = 1;
$file = "counter.txt ";
//File name
//That's it
if( ! file_exists( "$file " ) ) {
touch( "$file " );
chmod( "$file ",0777);
$fp=fopen( "$file ", "r+ ");
fseek($fp,0);
$compteur = 0;
fputs($fp,$compteur);
}
if( is_readable( "$file ") and is_writable( "$file ") ) {
$fp=fopen( "$file ", "r+ ");
$compteur=fgets($fp,9999);
fseek($fp,0);
$compteur++;
fputs($fp,$compteur);
fclose($fp);
print $compteur;
} else {
chmod( "$file ",0777);
}
}
? >